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.

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 T.” [email protected]

Thanks and yes I have tried that. It does not bomb but nothing appears
when the form is displayed either :frowning:

2008/7/16 Sean C. Hess [email protected]:

What happens if you put the following before your code?

<%= :consultant_id %> - <%= session[:consultant_id] %>

Just making sure the variables are set the way you think they are.

On Tue, Jul 15, 2008 at 3:56 PM, Paul Jonathan T.
[email protected]

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 C. Hess [email protected]:

Thanks for the flattery. I’m a newbie myself, so it’s good to hear I
could
help somebody :smiley:
~sean

On Tue, Jul 15, 2008 at 4:23 PM, Paul Jonathan T.
[email protected]