1 – My controller is this , but this not call the view whit this name is login.html.erb, im not understand beacause what happen this , is to show the form of the login.
class FinancesController < ApplicationController
# GET /finances
# GET /finances.json
def login
@user = User.find_by_name(params[:user])
if @user
session[:user_id] = @user.id
redirect_to :action => 'index'
else
redirect_to login_url
end
end
def index
@finances = Finance.all(:order => "created_at")
respond_to do |format|
format.html # index.html.erb
format.json { render json: @finances }
end
end
2 – Someone can talk to me to use the authenticate method to validate a sample login whit user and password forms some, can show to me how use this method , the find_by_name_and_password dont works.
I thanks by the answers, many.
Routes.rb
Controle::Application.routes.draw do
match 'login' => 'finances#login'
resources :finances
end
check for the
@userobject.because, as of your code it will redirect to your
loginmethod if@useris not available.To render
login.html.erbfromloginmethod, there is no need for any manual redirections.