问题描述:

I changed my form from using form_tag to using form..then login button could no longer submit to users account... someone help me figure out what the problem is.

view/sessions/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>

sessions controller below

 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

Routes file code below

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

网友答案:

You have to use the <%= form_tag( { :action => :save, }, { :method => :post }) %> if you are using it in an erb file. Your rails controller will not understand plain html form tags.

相关阅读:
Top