ruby - How to call model method in rails controller -


hi have call model method in controller , view. had done this:

category.rb

def self.category_list     category = self.all.collect { |m| [m.name, m.id] }     return category end 

products_controller.rb

def new     @product = product.new     @category = category.category_list end 

and in products/new.html.erb

<%= form_for @product, action: "create", :html => {:class => "form-group"} |f| %>         <div class="fields">           <%= f.label :model_name %>           <%= f.text_field :model_name, :class => "form-control" %>         </div>         <div class="fields">           <%= f.label :model_number %>           <%= f.text_field :model_number, :class => "form-control" %>         </div>         <div class="fields">           <%= f.label :model_number %>           <%= f.select(:category_id, @category, :prompt => 'select') %>         </div>         </br>         <div class="actions">           <%= f.submit "submit", :class => "btn btn-success" %>         </div> <% end %> 

whem giving gives me error activerecord::dangerousattributeerror in productscontroller#new please guide how solve this. in advance :)

please change model method writes this

def self.category_list     category.all.collect { |c| [c.name, c.id] }   end 

and using field model_name because of giving error of dangerous attributes error please change name hope work.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -