登录按钮无效

时间:2015-05-18 08:40:13

标签: twitter-bootstrap ruby-on-rails-4

我将表单从使用form_tag更改为使用表单..然后登录按钮无法再提交给用户帐户...有人帮我弄清问题是什么。

查看/会话/ new.html.erb

<form class="form-horizontal">
  <fieldset>
    <legend>Admin Login</legend>
    <div class="form-group">
      <label for="inputEmail" class="col-lg-2 control-label">Email</label>
      <div class="col-lg-10">
        <input class="form-control" id="inputEmail" placeholder="Email" type="text">
      </div>
    </div>
    <div class="form-group">
      <label for="inputPassword" class="col-lg-2 control-label">Password</label>
      <div class="col-lg-10">
        <input class="form-control" id="inputPassword" placeholder="Password" type="password">
      </div>
    </div>
    <div class="form-group">
      <div class="col-lg-10 col-lg-offset-2">
        <button type="submit" class="btn btn-primary">Login</button>
      </div>
    </div>
  </fieldset>
</form>

下面的会话控制器

    class SessionsController < ApplicationController
   #skip_before_filter :authorize
  def new
  end

  def create
   user = User.find_by_email(params[:email])
   if user && user.authenticate(params[:password])
    session[:user_id] = user.id
    redirect_to '/'
  else
    redirect_to '/login'
  end
end

  def destroy
    session[:user_id] = nil
    redirect_to '/login'
  end
end

路由下面的文件代码

Rails.application.routes.draw do
  root to: 'dashboard#index'

  get '/login' => 'sessions#new'
  post '/login' => 'sessions#create'
  get '/logout' => 'sessions#destroy'

  get '/signup' => 'users#new'
  post '/users' => 'users#create'



  resources :applicants do
    root :to => 'applicants#index'
  end
end

1 个答案:

答案 0 :(得分:0)

你必须使用 <%= form_tag( { :action => :save, }, { :method => :post }) %> 如果你在erb文件中使用它。你的rails控制器不会理解普通的html表单标签。