I am the getting the following error when hitting my home page. I've spent hours trying to figure it out with no luck. Looking at the debug output it seems that the member_session object is not picking up any of the methods available on the member object class.
This page contains two forms, one for registering and one for logging in.
NoMethodError in Members#new
Showing /home/thomas/railsProjects/draughtsWorld/app/views/common/_loginPanel.html.erb where line #23 raised:
Model MemberSession does not respond to nickname
Extracted source (around line #23):
20:
21: <div class="">
22: <%= f.label :nickname, "Nickname" %>
23: <%= f.text_field :nickname, :class => "sign_in_textbox" %>
24: </div>
25:
26: <div class="">
Trace of template inclusion: app/views/members/new.html.erb
Rails.root: /home/thomas/railsProjects/draughtsWorld
Application Trace | Framework Trace | Full Trace
app/views/common/_loginPanel.html.erb:23:in `block in _app_views_common__login_anel_html_erb__835376200_89586240__736259602'
app/views/common/_loginPanel.html.erb:6:in `_app_views_common__login_anel_html_erb__835376200_89586240__736259602'
app/views/members/new.html.erb:7:in `_app_views_members_new_html_erb___591788923_89768980__1034002099开发者_如何学运维'
app/controllers/members_controller.rb:33:in `new'
member.rb
class Member < ActiveRecord::Base
acts_as_authentic
end
member_session.rb
class MemberSession < Authlogic::Session::Base
end
members_controller.rb:
class MembersController < ApplicationController
# GET /members
# GET /members.xml
def index
@members = Member.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @members }
end
end
# GET /members/new
# GET /members/new.xml
def new
@member = Member.new
@member_session = MemberSession.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @member }
end
end
member_sessions_controller.rb:
class MemberSessionsController < ApplicationController
def new
@member_session = MemberSession.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @member_session }
end
end
def create
@member_session = MemberSession.new(params[:member_session])
if @member_session.save
redirect_to root_url
else
format.html { render :action => "new" }
#render :action => :new
end
end
def destroy
@member_session = MemberSession.find
@member_session.destroy
redirect_to root_url
end
end
loginPanel.html.erb
<%= form_for @member_session, :html => { :class => "block" } do |f| %>
<%= debug(@member)%>
<%= debug(@member_session.methods)%>
<h4>Already Signed Up?</h4>
<% if @member_session.errors.any? %>
<ul>
<% @member_session.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<div class="">
<%= f.label :nickname, "Nickname" %>
<%= f.text_field :nickname, :class => "sign_in_textbox" %>
</div>
<div class="">
<%= f.label :password, "Password" %>
<%= f.password_field :password, :class => "sign_in_textbox" %>
</div>
<p class="submit">
<%= f.submit "Login", :class => "submit_button" %>
</p>
<p class="lost_password">
<a href="">Forgot you login details?</a>
</p>
<% end %>
This is an answer:
Model MemberSession does not respond to nickname
Does Member has column nickname
?
I think this it should be either username
or login
, so try to change yours view to:
<%= f.label :username, "Nickname" %>
<%= f.text_field :username, :class => "sign_in_textbox" %>
or
<%= f.label :login, "Nickname" %>
<%= f.text_field :login, :class => "sign_in_textbox" %>
EDIT: Or you can try to specify column name in authlogic configuration:
acts_as_authentic do |c|
c.login_field = :nickname
end
It should do the job.
精彩评论