Ruby on Rails - Send two text_field_tag values present inside form_for in hash format -
i have form_for have field related form object , there fields not related form object field using text_field_tag. field key - value pair, when submitting form, want combine or rather send in hash format in controller code can save these values together.
here form_for code
[demo]
<%= form_for [@var], :url => {:action => form_action}, :html => {:id => form_id} |f| %> <table border=0 cellpadding="0" cellspacing="8" id='psp-config-form' > <tr class='psp_config_row'> <td><label for=''>screen label</label></td> <td> <%= text_field_tag "screen_label[]", "", :size => 20, :class => 'search-txt-input', :maxlength => 360 %> </td> <td><label for=''>value</label></td> <td> <%= text_field_tag "screen_value[]", "", :size => 20, :class => 'search-txt-input', :maxlength => 360 %> </td> <td><label for=''>mask value</label></td> <td> <%= check_box_tag "is_masked[]", "", false, :class => 'search-txt-input' %> </td> <td> <%= link_to 'delete', "javascript:void(0);", :class => 'linkclass delete_link', :title => 'confirmation', :style=>"display: none" %> </td> </tr> <tr> <td></td> <td class="add_psp_config_button"> <%= link_to "add additional psp credentials", "javascript:void(0);", :title => "add psp config values", :class => "actionbtn button", :id => "add_psp_config_button" %> <td> </tr> <tr> <td></td> <td> <%= f.submit 'add psp',:class => 'loginbtn', :id => 'add-psp-button'%> </td> <td> <%= text_field_tag 'cancel', 'cancel', :type=> 'button', :class => 'loginbtn' %> </td> </tr>
here current params sent controller:
parameters: {"utf8"=>"?", "authenticity_token"=>"smzytnbygxf3idtyrovafhxwzftm4u8+v5xoyfgr5/8=", "psp_admin_portal"=>{"psp_name"=>"google", "psp_url"=>"https://google.com", "psp_username"=>"google-username", "psp_password=>"xxxx"}, "screen_label"=>["label1", "label2", "label3"], "screen_value"=>["val1", "val2", "val3"], "commit"=>"add psp"}
so here finding way using can send screen_lable , value params this:
{screen_params => {"label1" => "val1", "label2" => "val2"}, ...}
let me know if of have idea on this.
thanks, dean
try using object_name method on form object below,
<%= text_field_tag "#{f.object_name}[your_variable_name]", "", :size => 20, :class => 'search-txt-input', :maxlength => 360 %>
if submit now, form object's hash have element, "your_variable_name" => "value_entered_in_text_box".
Comments
Post a Comment