In my app I Have check boxes and want to save checkbox value once check box tick and page reload. Here is my custom_field_update action.
def custom_field_update
begin
val = params[:field_value]
alt = params[:alt_text]
if alt
if alt.kind_of?(Array)
alt = alt.join(',')
end
else
alt = ""
end
if val.kind_of?(Array)
val = val.join(',')
end
@url = api_version_root+'/startups/fields/'+params[:sid]
response = RestClient.put @url,
{ startup_field: {
id: params[:sid],
alt_text: alt,
field_value: val,
user_id: current_user
}
}, api_token_hash
flash[:info] = "Custom field updated."
redirect_to :back and return
rescue RestClient::ExceptionWithResponse => err
handle_rest_error http_code: err.http_code
end
end
Here is my checklist
<%= form_tag({controller: "srm", action: "custom_field_update"}, method: "post", multipart: true ) do %>
<input type="hidden" name="sid" value="<%= m["id"] %>">
<% templat = @custom_templates.select{|s| s["id"] == m["startup_field_template_id"]}.first%>
<small>
<% vals = field["options"].to_s.gsub(/[\[\"\]]/, '').split(',') %>
<% vals.each do |v| %>
<% if val.include?(v.to_s) %>
<input type="checkbox" checked="checked" /> <%= v %><br/>
<% else %>
<% if templat["option_multi"] %>
<input type="checkbox" /> <%= v %><br/>
<% else %>
<input type="checkbox" class="check" id="check"/> <%= v %><br/>
<% end %>
<% end %>
<% end %>
</small>
<% end %>
But this is not work. Can anyone help me for this?
Aucun commentaire:
Enregistrer un commentaire