I know this is a basic problem with a very simple solution but I''m new to ruby and rails so I''m a bit confused why this isn''t working I want to be able to create a select tag which is linked with a particular model, so I used this code in the view <%= start_form_tag :action => ''index''%> <%= text_field("user", "user_name")%> <%options = [["","0"], ["Low","1"],["High","2"]]%> <%=select("user", "level", options)%> <%= submit_tag ''test''%> <%= end_form_tag %> here''s the controller code class TestController < ApplicationController def index @user = User.find_by_id(params[:id]) end end I tested the above code using a user record with the field level containing 2 and the select list did not default to 2 but stayed at the empty option As I said before, I''m sure I''m missing something obvious here but I haven''t a clue what, any ideas? Cheers Teesea --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Add The following to the top of the file. <HR><PRE><%=params[:user].inspect -%></pre><HR> Check to see what level is set to. Frefesh the page to see changes to a form can be problimatic as well, as the browser will often remember what it was set to. (this drives me nuts when dealing with default values) teesea wrote:> I know this is a basic problem with a very simple solution but I''m new > to ruby and rails so I''m a bit confused why this isn''t working > > I want to be able to create a select tag which is linked with a > particular model, so I used this code in the view > > <%= start_form_tag :action => ''index''%> > > <%= text_field("user", "user_name")%> > <%options = [["","0"], ["Low","1"],["High","2"]]%> > <%=select("user", "level", options)%> > > <%= submit_tag ''test''%> > > <%= end_form_tag %> > > here''s the controller code > > class TestController < ApplicationController > > def index > @user = User.find_by_id(params[:id]) > end > > end > > I tested the above code using a user record with the field level > containing 2 and the select list did not default to 2 but stayed at > the empty option > > As I said before, I''m sure I''m missing something obvious here but I > haven''t a clue what, any ideas? > > Cheers > > Teesea-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the tip, turns out the problem was that the field was of type int but the option values i was giving rails were strings, I didnt realise that it checked type when doing that, doh! On Feb 26, 6:37 pm, David Harkness <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Add The following to the top of the file. > <HR><PRE><%=params[:user].inspect -%></pre><HR> > Check to see what level is set to. > > Frefesh the page to see changes to a form can be problimatic as well, as > the browser will often remember what it was set to. (this drives me nuts > when dealing with default values) > > > > teesea wrote: > > I know this is a basic problem with a very simple solution but I''m new > > to ruby and rails so I''m a bit confused why this isn''t working > > > I want to be able to create aselecttagwhich is linked with a > > particular model, so I used this code in the view > > > <%= start_form_tag :action => ''index''%> > > > <%= text_field("user", "user_name")%> > > <%options = [["","0"], ["Low","1"],["High","2"]]%> > > <%=select("user", "level", options)%> > > > <%= submit_tag ''test''%> > > > <%= end_form_tag %> > > > here''s the controller code > > > class TestController < ApplicationController > > > def index > > @user = User.find_by_id(params[:id]) > > end > > > end > > > I tested the above code using a user record with the field level > > containing 2 and theselectlist did not default to 2 but stayed at > > the empty option > > > As I said before, I''m sure I''m missing something obvious here but I > > haven''t a clue what, any ideas? > > > Cheers > > > Teesea > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jclark42796-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-01 01:49 UTC
Re: Select tag not defaulting to Models value
I just ran in to the same problem, I added the "to_s" to the end of c.id and that fixed the problem <p><label for="question_category">Category</label><br/> <%= select("question", "category_id", Category.find(:all, :order => "description").collect {|c| [ c.description, c.id.to_s ] }) %> I''m surprised rails doesn''t handle this for you when creating the select. Jim On Feb 26, 5:57 pm, "teesea" <t.co...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the tip, turns out the problem was that the field was of > type int but the option values i was giving rails were strings, I > didnt realise that it checked type when doing that, doh! > > On Feb 26, 6:37 pm, David Harkness <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Add The following to the top of the file. > > <HR><PRE><%=params[:user].inspect -%></pre><HR> > > Check to see what level is set to. > > > Frefesh the page to see changes to a form can be problimatic as well, as > > the browser will often remember what it was set to. (this drives me nuts > > when dealing with default values) > > > teesea wrote: > > > I know this is a basic problem with a very simple solution but I''m new > > > to ruby and rails so I''m a bit confused why this isn''t working > > > > I want to be able to create aselecttagwhich is linked with a > > > particular model, so I used this code in the view > > > > <%= start_form_tag :action => ''index''%> > > > > <%= text_field("user", "user_name")%> > > > <%options = [["","0"], ["Low","1"],["High","2"]]%> > > > <%=select("user", "level", options)%> > > > > <%= submit_tag ''test''%> > > > > <%= end_form_tag %> > > > > here''s the controller code > > > > class TestController < ApplicationController > > > > def index > > > @user = User.find_by_id(params[:id]) > > > end > > > > end > > > > I tested the above code using a user record with the field level > > > containing 2 and theselectlist didnotdefault to 2 but stayed at > > > the empty option > > > > As I said before, I''m sure I''m missing something obvious here but I > > > haven''t a clue what, any ideas? > > > > Cheers > > > > Teesea > > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jclark42796-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-01 03:08 UTC
Re: Select tag not defaulting to Models value
Nevermind :-) My category_id was a string...oops. On Feb 28, 8:49 pm, "jclark42...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jclark42...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I just ran in to the same problem, I added the "to_s" to the end of > c.id and that fixed the problem > > <p><label for="question_category">Category</label><br/> > <%= select("question", "category_id", Category.find(:all, :order => > "description").collect {|c| [ c.description, c.id.to_s ] }) %> > > I''m surprised rails doesn''t handle this for you when creating the > select. > > Jim > > On Feb 26, 5:57 pm, "teesea" <t.co...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for the tip, turns out the problem was that the field was of > > type int but the option values i was giving rails were strings, I > > didnt realise that it checked type when doing that, doh! > > > On Feb 26, 6:37 pm, David Harkness <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > Add The following to the top of the file. > > > <HR><PRE><%=params[:user].inspect -%></pre><HR> > > > Check to see what level is set to. > > > > Frefesh the page to see changes to a form can be problimatic as well, as > > > the browser will often remember what it was set to. (this drives me nuts > > > when dealing with default values) > > > > teesea wrote: > > > > I know this is a basic problem with a very simple solution but I''m new > > > > to ruby and rails so I''m a bit confused why this isn''t working > > > > > I want to be able to create aselecttagwhich is linked with a > > > > particular model, so I used this code in the view > > > > > <%= start_form_tag :action => ''index''%> > > > > > <%= text_field("user", "user_name")%> > > > > <%options = [["","0"], ["Low","1"],["High","2"]]%> > > > > <%=select("user", "level", options)%> > > > > > <%= submit_tag ''test''%> > > > > > <%= end_form_tag %> > > > > > here''s the controller code > > > > > class TestController < ApplicationController > > > > > def index > > > > @user = User.find_by_id(params[:id]) > > > > end > > > > > end > > > > > I tested the above code using a user record with the field level > > > > containing 2 and theselectlist didnotdefault to 2 but stayed at > > > > the empty option > > > > > As I said before, I''m sure I''m missing something obvious here but I > > > > haven''t a clue what, any ideas? > > > > > Cheers > > > > > Teesea > > > > -- > > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---