0

我想在登录表单中执行此操作,
我只想在用户提交数据时保留数据,但这是无效的。

下面的代码:

在控制器中:

def login

    if request.request_method == "POST"
        @session = params[:session]
    end

    render "login",
           :layout => "admin_login"
end

admin_login模板:

= form_for :session, :url => { :action => "login", :controller => "administrator" }, :html => { :class => "form-horizontal" } do |f|

  %div.control-group
    #{f.label :token, "User / Email", :class => "control-label" }
    %div.controls
      #{f.text_field :token}

  %div.control-group
    #{f.label :password, "Password", :class => "control-label" }
    %div.controls
      #{f.password_field :password}

但是当我提交表单时它会抛出异常,说undefined method 'token'

谢谢

4

1 回答 1

0

如果您不处理资源,则应使用form_tag

= form_tag { action: 'login', controller: 'administrator' }, class: 'form-horizontal' do
  %div.control-group
    %label.control-label User / Email

    %div.controls
      = text_field_tag :token

  %div.control-group
    %label.control-label Password

    %div.controls
      = password_field_tag :password
于 2013-03-13T07:28:34.613 回答