Search code examples
ruby-on-rails-3remote-forms

rails 3 form remote


I am write:

<%= form_for(current_user, :remote => true) do %>
  <p>
    <%= label_tag t("language") %>: 
    <%= select_tag "language", options_for_select([["Русский", "rus"], ["English", "eng"]]) %>
  </p>

  <p><%= submit_tag t "options.save" %></p>
<% end %>

Inspector: http://deeflow.com/changer/inspect.png

Content: http://deeflow.com/changer/content.png

But, value in db doesn't updated


Solution

  • <%= form_for(current_user, :remote => true) do |f| %>
      <p>
        <%= f.label :language, t("language") %>: 
        <%= f.select :language, options_for_select([["Русский", "rus"], ["English", "eng"]]) %>
      </p>
    
      <p><%= f.submit t "options.save" %></p>
    <% end %>
    

    Notice the variable |f| and change of label_tag, select_tag and submit_tag to f.label, f.select and f.submit

    In rails form_for and corresponding form_buider object(|f|) are used to group values under a common key, which rails can understand. *_tag helpers are generally used to pass unrelated parameters.