0

我正在尝试解决这个问题:

巫术和简单形式的实现

似乎我需要做的就是能够将 form_for 与巫术登录表单一起使用,而不是form_tag. 这将使我能够使用simple_form_for.

你怎么做到这一点?

4

1 回答 1

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 %>
于 2013-01-03T15:49:41.593 回答