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
the third argument is defaulted to false so your radio buttons start as
not
checked.
you need to check at least one before the form can submit the value of
the
radio
button you checked.
You might also want to check your code below.
def destroy
$score= params[:exp];
Someone correct me if I’m wrong but it’s not good practice to prepend a
variable with $ in ruby.
if params[:exp] = ‘1’
The line above sets params[:exp] to ‘1’ so @ac below will always be
equal
to ‘1’
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.
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
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).
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| %>
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.
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.
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.
So it doesn’t sound like it’s “working well” to me
Why are you doing this form by hand? I’d recommend you read up
on Rails forms, including the radio_button method.
Are you certain that the submit action is saving the input to some
persistent storage?