你可以使用form_for和sorcery登录表单而不是form_tag

时间:2012-09-16 20:53:02

标签: ruby-on-rails simple-form sorcery

我正试图解决这个问题:

Sorcery and Simple Form implementation

似乎我需要做的就是能够使用带有魔法登录表单的form_for而不是form_tag。这将使我能够使用simple_form_for

你是怎么做到的?

1 个答案:

答案 0 :(得分:2)

我使用@user变量:

我的会话控制器:

class UserSessionsController < ApplicationController
  skip_before_filter :require_login, :except => [:destroy]

  def new
    @user = User.new
  end

  def create
    if @user = login(params[:user][:username],params[:user][:password],false)
      redirect_back_or_to(root_path, :notice => 'Login successfull.')
    else
      @user = User.new
      flash.now[:error] = "Login failed."; render :action => "new"
    end
  end

  def destroy
    logout
    redirect_to(root_path, :notice => 'Logged out!')
  end
end

我的会话视图:

<%= simple_form_for @user,  :html => {:class => 'form-signin'} , :url => {:controller =>   'user_sessions', :action => 'create'} do |f| %>

  <%= f.input :username %>

  <%= f.password_field :password %>  

  <%= f.button :submit, 'Login' %>
<% end %>