开发者

Rails 2: Is it possible to develop a form.select linked to a returning value of an helper method?

开发者 https://www.devze.com 2023-03-04 16:35 出处:网络
I have a controller named store_controller.rb and method index that renders index.html.erb, displaying some products. I\'m thinking about the chance of placing in this view a form.select (a sort of dr

I have a controller named store_controller.rb and method index that renders index.html.erb, displaying some products. I'm thinking about the chance of placing in this view a form.select (a sort of drop-down menu) with values like (high price items, economic items). I want these values select products by a value returned by an helper method, that in call in view index.html.erb.

My question is: Developing this drop-down menu - using, for example, f.select - is it possible to link a drop-down menu in Rails to a value returned by an helper method? For example: <%= f.select :product, :returned_value_开发者_如何学Goby_helper_method [[title, value..]] %> and so on?


Try select_tag, to which you can add whatever options you like (search web for options_for_select and options_for_select_tag). This will be static, however. If you want dynamic, consider Unobtrusive JavaScript and form observers.

0

精彩评论

暂无评论...
验证码 换一张
取 消