2012-04-02 39 views
0

我想知道如何在observe_field方法中传递ruby变量。在observe_field方法中传递ruby变量

我有以下:

<% action_parameter = params[:action] %> 

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

“action_parameter”是一个变量,我想通过在的observe_field方法,但上面的代码似乎不工作其值。

有什么建议吗?

回答

1

试试这个 <%action_parameter =参数[:行动]%>

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

Ruby的变量将在<%工作....%>

你可以使用插值,试试这个:

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