Paul Jonathan Thompson
2008-Jul-15 21:40 UTC
Newbie Question: Howto insert a variable into a new form
I am trying to populate some fields in a new form before I display it. I know that if I do this: @mapper = Mapper.new(:consultant_id => ''Fred'') It works and Fred is displayed in the form but in this case consultant_id is stored as a variable in sessions as it is assigned when the consultant logs in. So what I want to do is substitute "Fred" with my session variable: session[:consultant_id] If I do this: @mapper = Mapper.new(:consultant_id => ''#{session[:consultant_id]}'') The code appears in the form not the name. I have tried a number of other ways but they all caused the app to bomb. Can someone please show me the correct way to do this. Thanks, Paul Thompson. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sean Clark Hess
2008-Jul-15 21:45 UTC
Re: Newbie Question: Howto insert a variable into a new form
Have you tried just the following? I''ve never use Mapper, so I don''t know of any caveats that might apply to it specifically @mapper = Mapper.new(:consultant_id => session[:consultant_id]) On Jul 15, 3:40 pm, "Paul Jonathan Thompson" <rails...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to populate some fields in a new form before I display it. > > I know that if I do this: @mapper = Mapper.new(:consultant_id => ''Fred'') > > It works and Fred is displayed in the form but in this case > consultant_id is stored as a variable in sessions as it is assigned > when the consultant logs in. > So what I want to do is substitute "Fred" with my session variable: > session[:consultant_id] > > If I do this: @mapper = Mapper.new(:consultant_id => > ''#{session[:consultant_id]}'') > > The code appears in the form not the name. I have tried a number of > other ways but they all caused the app to bomb. > Can someone please show me the correct way to do this. > > Thanks, > > Paul Thompson.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Jonathan Thompson
2008-Jul-15 21:56 UTC
Re: Newbie Question: Howto insert a variable into a new form
Thanks and yes I have tried that. It does not bomb but nothing appears when the form is displayed either :-( 2008/7/16 Sean Clark Hess <seanhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Have you tried just the following? I''ve never use Mapper, so I don''t > know of any caveats that might apply to it specifically > > @mapper = Mapper.new(:consultant_id => session[:consultant_id]) >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sean Clark Hess
2008-Jul-15 21:59 UTC
Re: Newbie Question: Howto insert a variable into a new form
What happens if you put the following before your code? <div><%= :consultant_id %> - <%= session[:consultant_id] %></div> Just making sure the variables are set the way you think they are. On Tue, Jul 15, 2008 at 3:56 PM, Paul Jonathan Thompson <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks and yes I have tried that. It does not bomb but nothing appears > when the form is displayed either :-( > > 2008/7/16 Sean Clark Hess <seanhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > Have you tried just the following? I''ve never use Mapper, so I don''t > > know of any caveats that might apply to it specifically > > > > @mapper = Mapper.new(:consultant_id => session[:consultant_id]) > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Jonathan Thompson
2008-Jul-15 22:23 UTC
Re: Newbie Question: Howto insert a variable into a new form
Sean, thanks for your help. Your first suggestion: @mapper Mapper.new(:consultant_id => session[:consultant_id]) works just fine. What happened is that I save the data to sessions via a before filter in application.rb Somehow I forgot to run the filter and this came to light when your second suggestion failed to work. Thanks for the help, I am not a programming noob but still very much a noob to rails and object orientated programming. If I were confident in my code, I would likely have picked up the problem earlier but not being sure about the code, when it failed I just zeroed in on it. Thank you once again. It is guys like you that make the rails community great thing it is today. 2008/7/16 Sean Clark Hess <seanhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> What happens if you put the following before your code? > <div><%= :consultant_id %> - <%= session[:consultant_id] %></div> > Just making sure the variables are set the way you think they are. >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sean Clark Hess
2008-Jul-15 22:25 UTC
Re: Newbie Question: Howto insert a variable into a new form
Thanks for the flattery. I''m a newbie myself, so it''s good to hear I could help somebody :D ~sean On Tue, Jul 15, 2008 at 4:23 PM, Paul Jonathan Thompson <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Sean, thanks for your help. Your first suggestion: @mapper > Mapper.new(:consultant_id => session[:consultant_id]) works just fine. > What happened is that I save the data to sessions via a before filter > in application.rb Somehow I forgot to run the filter and this came to > light when your second suggestion failed to work. > > Thanks for the help, I am not a programming noob but still very much a > noob to rails and object orientated programming. If I were confident > in my code, I would likely have picked up the problem earlier but not > being sure about the code, when it failed I just zeroed in on it. > > Thank you once again. It is guys like you that make the rails > community great thing it is today. > > 2008/7/16 Sean Clark Hess <seanhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > What happens if you put the following before your code? > > <div><%= :consultant_id %> - <%= session[:consultant_id] %></div> > > Just making sure the variables are set the way you think they are. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---