0

这是我的登录表格

<%= form_for Customer.new, url: {action: :login} do |f| %>
    <%= f.text_field :username,placeholder: 'Username or Email' %>
    <%= f.password_field :password,placeholder: 'Password' %>
    <%= f.submit 'Login' %>
<% end %>

这是我的控制器

def login
    username = params[:username]
    password = params[:password]
    unless username.blank? && password.blank?
      #My code doesn't entering to this block
    end
end

如果我提交表单它只是提交它不执行任何操作

编辑 1

这是提交表单时我的控制台返回的内容

Started POST "/auth/login" for 127.0.0.1 at 2013-09-08 08:23:05 +0530
Processing by AuthController#login as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"9f7TKlIspKQwX7jMSzI7XGrabgJKvnzj8Ip0OLTDtW4=", "customer"=>{"username"=>"xxx", "password"=>"[FILTERED]"}, "commit"=>"Login"}
  Rendered auth/login.html.erb within layouts/application (3.5ms)
  Rendered layouts/_header.html.erb (0.4ms)
Completed 200 OK in 21ms (Views: 19.3ms | ActiveRecord: 0.0ms)
4

1 回答 1

0

如果你检查你的params哈希,你会发现这些键不存在。相反,您会看到它params[:custpmer]确实包含这些字段。这就是 rails 以样式构建参数的form_for方式。所以试试这个:

username = params[:customer][:username]
password = params[:customer][:password]
于 2013-09-08T02:30:29.173 回答