0

这是我的应用程序的登录页面,但为用户选择的角色没有反映在数据库中,所以我想尝试将 form_for 更改为 form_tag 以查看数据是否被提交。

 <%= form_for(@user) do |f| %>
      <% if @user.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
          <ul>
            <% @user.errors.full_messages.each do |msg| %>
              <li><%= msg %></li>
            <% end %>
          </ul>
        </div>
      <% end %>
      <div class="field">
        <%= f.label :email %><br />
        <%= f.text_field :email %>

      </div>
      <div class="field">
        <%= f.label :username %><br />
        <%= f.text_field :username %>
      </div>
      <% if @current_method == "new" %>
        <div class="field">
          <%= f.label :password %><br />
          <%= f.password_field :password %>
        </div>
        <div class="field">
          <%= f.label :password_confirmation %><br />
          <%= f.password_field :password_confirmation %>
        </div>
      <% end %>
      <% for role in Role.find(:all) %>
        <div>
          <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %>
          <%= role.name %>
        </div>
      <% end %>
      <div class="actions">
        <%= f.submit %>
      </div>
    <% end %>
4

1 回答 1

0
<%= form_tag users_path, methods=> post:do %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
      <ul>
        <% @user.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  <div class="field">
    <%= label_tag 'email' %><br />
    <%= text_field_tag :email, params[:email], :placeholder => "Email" %>
  </div>
  <div class="field">
    <%= label_tag 'username' %><br />
    <%= text_field_tag :username, params[:username], :placeholder => "Username" %>
  </div>
  <% if @current_method == "new" %>
    <div class="field">
      <%= label_tag :password %><br />
      <%= password_field_tag 'password' %>
    </div>
    <div class="field">
      <%= label_tag :password_confirmation %><br />
      <%= f.password_field_tag 'password_confirmation' %>
    </div>
  <% end %>
  <% for role in Role.find(:all) %>
    <div>
      <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %>
      <%= role.name %>
    </div>
  <% end %>
  <div class="actions">
 <%= submit_tag 'submit' %>
  </div>
<% end %>
于 2012-04-23T08:42:37.380 回答