表单提交而不执行任何操作rails

时间:2013-09-08 02:18:32

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1

这是我的登录表单

<%= 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)

1 个答案:

答案 0 :(得分:0)

如果您检查params哈希,则会看到这些密钥不存在。相反,您会看到params[:custpmer]执行此操作并且包含这些字段。这就是rails以form_for风格构建params的方式。所以试试这个:

username = params[:customer][:username]
password = params[:customer][:password]