开发者

Rails Radio Button returning Nil

I'm trying to pass a value from a radio button group in my view to a method in my controller. I've looked up many different ways of doing this and I get the same result, nil. So far I have:

In view

    <div id = "oilchange_buttons">
    <br><%= radio_button_tag 'oilchange', '0' %> Complete
    <%= radio_button_tag 'oilchange', '1' , true %> Pending
    </div>

<%= link_to 'Update', :remote => true, :action => 开发者_如何学Go"there" , :submit => 'oilchange_buttons' , > :id=> @huntingtonflatbedboxtruck %>

In controller

def there
if params[:oilchange] == '0'
Do stuff
end 

At this point in the controller all I get is nil rather than a value. I'm stuck and have no clue what else to try. I'm still fairly new to rails, I'm probably missing something fundamental. Thanks!


You need to create a form, otherwise your Update button, does not send the (form) information.

For more information on forms take a look at this guide


You need form_tag. If this is your first time to create any form in Rails, I'd suggest you read the link @Veger provided and http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag.

You need :remote for form_tag the method, not for link_to().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜