i m trying to read the input of the radio button and compare it with a
string and further increment a count variable as per the result of
comparison.i e used
i corrected the "if params[:exp] == '1'".
but i want to save the input got from the radio button to an variable
so that i can compare it with another string and with the result of the
comparison i need to increment a count variable SO so i thought i ve no
other way other than global variable to use it across views and
controllers.But even when i tried the $ way ,@@ way @ way , when I
assign params[:exp] to it it is not getting displayed.Kindly suggest me
a alternative solution.
If this is on a per-user basis, you can save your counter value in the
session; if it's global to the entire app you can use the DB or another
persistent storage (e.g. MongoDB, Redis).
hi
Thanks for ur reply, It was useful. i ve chaged my view in html as
follows
<br>
<form>
<br>
<input type="radio" name="radios1"
onclick=this.parentNode.submit() value="<%=@abc.a%>"><%=@abc.a%>
<input type="radio" name="radios1"
onclick="this.parentnode.submit()" value="<%=@abc.b%>"><%=@abc.b%>
<input type="radio" name="radios1"
onclick="this.parentnode.submit()" value="<%=@abc.c%>"><%=@abc.c%>
<input type="radio" name="radios1" onclick="this.parentnode.submit()"
value="<%=@abc.d%>"><%=@abc.d%>
</form>
The code is workin well except that, as soon as a radio button is
selected the the page gets refreshed and the selection is not reflected
in that page after that. i need the selection to be visible even after
the onclick event and also when "history.back" is done.Please do help
Thank for ur reply
i m not sure about how to write the form for this radio_button. if i use
the form_for @abc where abc is the database i m not able to read input
with params[:]. i did use the form as
<%= form_for(@abc) do |f| %>
<tr><%=f.radio_button:e,@abc.a%> <%=f.label:rating_1,@abc.a%></tr>
<tr><%=f.radio_button:e,@abc.b%> <%=f.label:rating_1,@abc.b%></tr>
<tr><%=f.radio_button:e,@abc.c%> <%=f.label:rating_1,@abc.c%></tr>
<%=f.radio_button:e,@abc.d%> <%=f.label:rating_1,@abc.d%>
where the answer selected would get updated to the database. as you said
i don want to update it in the database . i need to modify this form to
a way where i need to read the value of the selection and inmcrement the
counter on per user basis.
This is making less sense as we go: 'abc is the database'?? I totally
don't understand that.
Is the thing represented by 'abc' an object or an attribute of an object?
And if an object, you're saying you don't want it to be an ActiveRecord-
derived object? A more realistic example would help me, at least
Also, the markup above isn't remotely valid, so you may want to fix
that long the way.