views:

38

answers:

1

I'm trying to use some radio buttons to be selected and use the parameter as a find condition for my model... SO far I have. View

<% form_tag do %>
<p> <%= radio_button_tag :interest,  "apple" %> Apple </p>
<p> <%= radio_button_tag :interest, "orange" %> Orange </p>
<p> <%= radio_button_tag  :interest, "peach" %> Peach </p>
<p> <%= radio_button_tag :interest, "banana" %> Banana </p>
<p> <%= submit_tag 'Choice' %> </p>
<% end %> 
<p>Result: <%= @result %></p>

how do i get @result = param[?], so it displays the value of the radiobuttons?

Eventually, I would to put the parameter into a find conditions where it would be something Fruit.find(:all, :type => "name LIKE ?", param[?])

I looked at http://stackoverflow.com/questions/623051/radio-buttons-on-rails but I didnt know how to make is a form so you I could read the parameter value

+1  A: 

You can always look at generated html. In this case (if you don't use prefixes), it should be like <input name="interest" ... >. So, you can fetch parameter values by params[:interest].

on comment
Pure html. You will find something similar if you check html generated by your rails tags.

<input name="interest" value="apple" type="radio"> Apple <br/>
<input name="interest" value="orange" type="radio"> Orange <br/>
...
Nikita Rybak
How would I do that? I mean is there a way I could do it with rails, so i can pass the values of any of the parameters as an object (determined but the value sent by the form) . so it would be params[:apples or oranges or etc? ]
ChrisWesAllen
In your controller code, call 'params[:interest]'. For debug purposes (to see the value in server log), you can do 'puts params[:interest]'.
Nikita Rybak
would I have to get rid of the form tag? I thought you had to have it in apps in rails?
ChrisWesAllen
**on your edited first comment** this has nothing to do with ruby. Browser for such list of radio buttons will send parameter in form "webpage.html?interest=orange". Not "orange=true" or anything else.
Nikita Rybak
**would I have to get rid of the form tag** If you wish. Rails form tag just generates html form tag and some inner content. You can as well write this content by hands.
Nikita Rybak
so if <input name="interest" ...> where do you set the values of oranges? Can you add an additional id element?
ChrisWesAllen