I am new to the Ruby on Rails application, I have already created CRUD, but I am still equipped with Loginand functions Logout.
This is my Session_controller:
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:passkey])
else
flash[:danger] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
It's my opinion: new.html.erb
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<%= f.label :passkey%>
<%= f.password_field :passkey, class: 'form-control' %>
<%= f.submit "Log in", class: "btn btn-primary" %>
<% end %>
This is my model:
class User< ActiveRecord::Base
validates :first_name, :presence => true, :length => { :in => 3..20 }
validates :last_name, :presence => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true, format: { with: /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/ }
validates :passkey, :confirmation => true, :length => {:in => 6..20}
end
When I click the login button, showing this error:
NoMethodError in SessionController # create undefined `authenticate 'method for #User:0x0000000d5c65e0>
How can I fix this error?
I use ruby 1.9.7 Rails 4.2.5andmysql2
That would help me a lot, please.