Hi All,

I am new to ruby on rails and i am able to select the value from select
box but after reloading the page the select box selected value is not
selected, please help me...


Thanks in Advance.

This is the code what i am using

<%= select("rnotes", "project_vno", Version.find(:all, :conditions =>
["project_id = ?", @project.id]).collect { |v| [ v.name, v.id ] },
options ={:prompt => "Select Version",:include_blank =>
"ALL"},><%= select("rnotes{:onchange =>
"window.location='rnote?vid='+this.value" }) %>

and the html display is

<select onchange="window.location='rnote?vid='+this.value"
name="rnotes[project_vno]" id="rnotes_project_vno">
<option value="">Select Version</option>
<option value="">ALL</option>
<option value="2">version 1.0</option>
<option value="3">version 1.1</option>
<option value="7">version 1.2</option>
</select>

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

  • Walter Lee Davis at Jan 12, 2012 at 5:28 pm

    On Jan 12, 2012, at 12:38 AM, NagaJeyanthi N. wrote:

    Hi All,

    I am new to ruby on rails and i am able to select the value from select
    box but after reloading the page the select box selected value is not
    selected, please help me...


    Thanks in Advance.

    This is the code what i am using

    <%= select("rnotes", "project_vno", Version.find(:all, :conditions =>
    ["project_id = ?", @project.id]).collect { |v| [ v.name, v.id ] },
    options ={:prompt => "Select Version",:include_blank =>
    "ALL"},><%= select("rnotes{:onchange =>
    "window.location='rnote?vid='+this.value" }) %>

    and the html display is

    <select onchange="window.location='rnote?vid='+this.value"
    name="rnotes[project_vno]" id="rnotes_project_vno">
    <option value="">Select Version</option>
    <option value="">ALL</option>
    <option value="2">version 1.0</option>
    <option value="3">version 1.1</option>
    <option value="7">version 1.2</option>
    </select>
    If you're posting this to itself, and you expect the select to default, you're going to have to name the GET parameter exactly the same as Rails named the select. Try changing the window.location part to

    "window.location='rnote?' + this.name + '=' + this.value"

    You may have to fiddle with this a bit, but the basic premise is that if you name the parameter exactly the same way that Rails would, When you come back to the form, that select will be defaulted to match.

    There is also another trick you could try, and that is the :default parameter to the select() method. Set that to the value, so in this case, params[:vid], and see if that does the same thing. Less changes in your code that way.

    Walter
    --
    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.
    --
    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
postedJan 12, '12 at 5:38a
activeJan 12, '12 at 5:28p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase