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

<%= form_for(@abc) do |f| %>
<div id="radio_buttons">
<%= radio_button_tag 'exp', 2 %>2
<%= radio_button_tag 'exp', 1 %>1
<%= link_to 'Submit now', {:action=>"destroy"},:remote => true, :submit
=>
'radio_buttons' %>
</div>
<%end%>

def destroy
$score= params[:exp];
if params[:exp] = '1'
@ac=params[:exp]
end
end
I m not able to see the parameter either $score or @ac

Kindly give me the solution

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Jim Ruther Nill at Dec 4, 2011 at 12:12 pm

    On Sun, Dec 4, 2011 at 7:38 PM, Guru R. wrote:

    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

    <%= form_for(@abc) do |f| %>
    <div id="radio_buttons">
    <%= radio_button_tag 'exp', 2 %>2
    <%= radio_button_tag 'exp', 1 %>1
    <%= link_to 'Submit now', {:action=>"destroy"},:remote => true, :submit
    =>
    'radio_buttons' %>
    </div>
    <%end%>
    From the api
    *radio_button_tag*(name, value, checked = false, options = {})

    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'

    @ac=params[:exp]
    end
    end
    I m not able to see the parameter either $score or @ac

    Kindly give me the solution

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Guru R. at Dec 4, 2011 at 2:20 pm
    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.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Hassan Schroeder at Dec 4, 2011 at 5:44 pm

    On Sun, Dec 4, 2011 at 6:19 AM, Guru R. wrote:

    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).

    HTH!
    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Guru R. at Dec 6, 2011 at 11:58 am
    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

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Hassan Schroeder at Dec 6, 2011 at 4:27 pm

    On Tue, Dec 6, 2011 at 3:58 AM, Guru R. wrote:

    <input type="radio" name="radios1"
    onclick=this.parentNode.submit() value="<%=@abc.a%>"><%=@abc.a%>
    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 :-)

    1) Why are you doing this form by hand? I'd recommend you read up
    on Rails forms, including the `radio_button` method.

    2) Are you certain that the submit action is saving the input to some
    persistent storage?

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Guru R. at Dec 7, 2011 at 4:15 am
    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.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Hassan Schroeder at Dec 7, 2011 at 6:08 pm

    On Tue, Dec 6, 2011 at 8:15 PM, Guru R. wrote:
    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.

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 4, '11 at 11:39a
activeDec 7, '11 at 6:08p
posts8
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase