Kim
Kim

Reputation: 2176

passing ruby variable in observe_field method

I would like to know how can I pass a ruby variable inside an observe_field method.

I have the following:

<% action_parameter = params[:action] %>

<%= observe_field :car_type,
                  :url => { :controller => 'cars',
                            :action => :display_subtypes },
                  :with => "'id=' + value + '&somevalue=' + action_parameter"
%>

'action_parameter' is a variable and I would like to pass its value in the observe_field method but the code above does not seem to work.

Any suggestion?

Upvotes: 0

Views: 111

Answers (2)

Hardik Patel
Hardik Patel

Reputation: 838

try this <% action_parameter = params[:action] %>

<%= observe_field :car_type,
                  :url => { :controller => 'cars',
                            :action => :display_subtypes },
                  :with => "'id=' + value + '&somevalue=#{action_parameter}'"
%>

Upvotes: 1

Vik
Vik

Reputation: 5961

Ruby variable will work in <% .... %>

you can use interpolation , Try this :

<%= observe_field :car_type,
                  :url => { :controller => 'cars',
                            :action => :display_subtypes },
                  :with => "id=#{value}&somevalue=#{action_parameter}"
%>

Upvotes: 1

Related Questions