Uninitialized constant ActionView :: CompiledTemplates :: Category

using this tutorial

http://railscasts.com/episodes/57-create-model-through-text-field

I need to make it work in my application, it was on rails 3.0.7, and it worked fine, updated it to 3.1.3, and now I got this error

uninitialized constant ActionView::CompiledTemplates::Category 

I will look for answers more time, but now I have a very short time. I looked at most of the Google results related to this problem and nothing good. Need help please.

the form

 <%= f.collection_select :category_id, Category.find(:all), :id, :name, :prompt => "Select a Category" %> or create one: <%= f.text_field :new_category_name %> 

model

 class Tvstation < ActiveRecord::Base belongs_to :category attr_accessor :new_category_name before_save :create_category_from_name def create_category_from_name create_category(:name => new_category_name) unless new_category_name.blank? end end 
+6
source share
3 answers

ok, only for others, if they fall into this stupid thing like me, don't forget to have category.rb in the app / models.

 class Category < ActiveRecord::Base ... end 
+22
source

For me, I have the same problem in the views. My category model is available in the namespace example.

  Module financial
   class Category
   end
 end

When I just call Category.get_method. This gave the same error. so I changed to Financial :: Category that solved my problem.

+3
source

I used PORO and did not boot, giving me this error. This happened because I changed the class name without changing the file name.

0
source

Source: https://habr.com/ru/post/915707/


All Articles