这是我的登录表单
<%= 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)
答案 0 :(得分:0)
如果您检查params
哈希,则会看到这些密钥不存在。相反,您会看到params[:custpmer]
执行此操作并且包含这些字段。这就是rails以form_for
风格构建params的方式。所以试试这个:
username = params[:customer][:username]
password = params[:customer][:password]