开发者

Ruby on Rails: Retrieve id of selection made in f.select

I have got a predefined selection list and i want to get the id of the selected item in the list.

My selection list is as follows:

Type: <%= f.select开发者_如何学Go(:SUB_TYPE, [['Type1', 't1'], ['Type2', 't2'], ['Type3', 't3'] ],{ :prompt => "Select the Type"}, {:onChange => "ShowTypeForm(this.value)"} ) %>

What i want to know is how to retrieve the id of the selection made, in ruby on rails

Many many thanks


If this is part of a form it will be sent through using the name provided. In this case it looks to be a parameter you've named SUB_TYPE but to be sure check your development logs when submitting. The params hash is listed there for each request.

As you have this operating on a form, the form will have an object that is being updated, so the parameters are grouped around that.

It may be as easy as:

# :example refers to the object the form was built around
selection_id = params[:example][:SUB_TYPE]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜