On 2 February 2012 15:14, Miquel Cubel <[email protected]> wrote: > Thanks for the answer > > El 02/02/2012 10:09, Colin Law escribió: > >> On 2 February 2012 08:50, Miquel Cubel<[email protected]> wrote: >>> >>> Hi, >>> >>> I have two doubts about the right way / place to write some code. >>> >>> Question 1: >>> I have a product and in the view I need to show a listbox with all >>> the >>> categories of this product. >>> - Option1: in the controller make "@product_categories = >>> ProductCategori.all" and later in the view make "<%= >>> f.collection_select(:product_category_id, @product_categories, :id, >>> :name) >>> %>" >>> - Option2: in the view just write "<%= >>> f.collection_select(:product_category_id, ProductCategori.all, :id, >>> :name) >>> %>" >> >> I would use option 1. The principle reason is that then if under some >> circumstances you don't want to show them all then the logic can go in >> the controller, leaving the view alone. > > I agree with this point of view, but in the other side, I find myself > repeating "@product_categories = ProductCategori.all" in several > controllers, like "new" and "edit",
Put it in a before_filter specifying the actions that need it. > and later I found that with default > scaffold, after submitting, if there is an error, this assignation doesn't > work well, and I don't understand exactly why (in rails 3.1.3). I think you had better ask about that in a different thread if you can't sort it out. Have you read the Rails Guide on Debugging which shows techniques for debugging your code. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

