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

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

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.

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.

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

~sean