2011-12-22 3 views
0

Ruby on Rails 양식에서 전달 된 매개 변수를 사용하는 Ruby 스크립트를 실행하려고합니다. 다음과 같이ruby ​​on rails은 폼에서 루비 스크립트로 매개 변수를 전달합니다.

</div> 
    <div class="actions"> 
     <%= button_to 'Apply Configs', :remote=>"true" %> 
    </div> 
<% end %> 

내 루비 스크립트의 구조는>

<%= form_for(@test, :html => {:name => "test", :id => "test"}) do |f| %> 
    <div class="field", id="configure_device"> 
     <%= f.label "Label1" %> 
     <%= f.text_field :Form_Param1 %> 
     <%= f.label "Label2" %> 
     <%= f.text_field :Form_Param2 %> 
     <%= f.label "Label3" %> 
     <%= f.text_field :Form_Param3 %> 

< ... 여기에 더 text_fields ... :

내에서의 코드 조각입니다

def apply_configs (param1, param2, param3, ..., etc.) 
    <... ruby code that executes based on the values passed in param1, param2, param3 ...> 
end 

이 Ruby 스크립트를 별도로 테스트했는데 올바른 입력 매개 변수 인 par 매개 변수 Form_Param1, Form_Param2, Form_Param3, ...을 전달할 수있는 방법은이 Ruby 스크립트를 어떻게 실행시킬 수 있습니까? .. 등은 param1, param2, param3, ... 등으로 매핑됩니까? 당신은 params에서받을 필요가

+4

의 필요 어떤 대답을 수락이 없습니다. – Reactormonk

답변

0

arguments

def apply_configs 
    form_param1 = params[:test][:Form_Param1] 
    form_param2 = params[:test][:Form_Param2] 

    // similarly 

    <... ruby code that executes based on the values passed in param1, param2, param3 ...> 
end 
+0

감사합니다. dku. 나는 그 변화를 만들었다. 나는 RoR의 초보자이므로 이제는 그 스크립트를 어떻게 폼에서 트리거 할 것인가? "def apply_configs ..."가 app/views/test 또는 그 밖의 다른 곳에서 apply_configs.rb 파일에 있다고 말하면, 버튼을 클릭 할 때 Ruby 스크립트가 실행되게하려면 button_to에서 무엇을 구성해야합니까? – rh4games

관련 문제