views:

36

answers:

2

Since 'HTML' do not have the attribute 'name',I am looking for a way to accept the value, which I populated in views, in the controller and assign it a variable name for another use. This is sample of my code:`

enter code here<form action="<%=url_for(:action =>:make_comment) %>">

<fieldset>
<select>
<%@category.each {|x|%>
<option id="label"> <%=x%></option>
 <%}%>
</select>
</fieldset>
<input type="submit" value="submit"/>
</form>`
+2  A: 

Are you saying that your html doesn't have a name attribute? If so, why?

The name attribute is what the server will interpret as the "key" for the value that you are sending. I don't know what other way you could try to go about doing this.

Maybe if you paste some code from your controller and your view, I could give a better answer.

Edit: After seeing your edited question, what you want to do is have your select tag with the name attribute, and your option tags have a value attribute with the value you want to send.

Hope this helps.

theIV
Sorry for that mistake. I am saying that the OPTION tag in HTML do not accept a name attribute, I just edited the question now with the code I am using.
Godwin
Thank you theIV. This has solved my problem.
Godwin
If it solved your problem, than you should reward theIV for his work, because that is how SO works. Please accept and if you want vote up his answer
jigfox
+2  A: 

This example show how you create a select tag:

select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {})

In this case, you would be able to get (in your controller) the value of the selected option through

params[:post][:person_id]

Is this what you want? Let me know if I misunderstood your question.

j.
Thank you very much. I have it now.
Godwin