refinerycms_membership
refinerycms_membership copied to clipboard
NoMethodError in MembersController#create undefined method `role_ids' for nil:NilClass
I'm receiving this error after member registration.
I believe it is related to the redirect_to(is_admin? ? admin_memberships_path : root_path )
call to is_admin?
that fails when calling !(current_user.role_ids & [REFINERY_ROLE_ID, SUPERUSER_ROLE_ID]).empty?
Any advice on how to overcome this?
Are those defined? Each of those constants corresponds to a role in the database.
B
On Sun, Sep 4, 2011 at 2:52 PM, michaelward82 < [email protected]>wrote:
I'm receiving this error after user registration.
I believe it is related to the
redirect_to(is_admin? ? admin_memberships_path : root_path )
call tois_admin?
that fails when calling!(current_user.role_ids & [REFINERY_ROLE_ID, SUPERUSER_ROLE_ID]).empty?
Any advice on how to overcome this?
Reply to this email directly or view it on GitHub: https://github.com/rbriank/refinerycms_membership/issues/25
In rails console
:
Load the user that was created by membership registration
> current_user = User.last
=> #<User id: 15, username: "[email protected]", email: "[email protected]", encrypted_password: "$2a$10$EIkfVTguTQuINMUYgELnmOn25Ty3cOGKrEn1NVSjuU21...", persistence_token: nil, created_at: "2011-09-04 18:48:17", updated_at: "2011-09-04 18:48:17", perishable_token: nil, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, sign_in_count: nil, remember_token: nil, reset_password_token: nil, remember_created_at: nil, first_name: nil, last_name: nil, title: nil, phone: nil, fax: nil, website: nil, organization: nil, street_address: nil, city: nil, province: nil, postal_code: nil, member_until: nil, membership_level: "Member">
> !(current_user.role_ids & [REFINERY_ROLE_ID, SUPERUSER_ROLE_ID]).empty?
=> false
It seems to me that current_user isn't being set.
I have found that modifying the create
method in members_controller.rb
and adding sign_in(@member)
fixes the problem.
At the moment I don't understand how this controller can function correctly without this modification. Is something going wrong in my setup?
def create
@member = Member.new(params[:member])
@member.username = @member.email
@member.membership_level = 'Member'
if @member.save
MembershipMailer.application_confirmation_member(@member).deliver
MembershipMailer.application_confirmation_admin(@member).deliver
sign_in(@member)
redirect_to(is_admin? ? admin_memberships_path : root_path )
else
@page = Page.find_by_link_url('/members/new')
@member.errors.delete(:username) # this is set to email
render :action => :new
end
end
I'd like to add you to my professional network on LinkedIn.
- Brian
Brian Kierstead Information Technology and Services Professional Ontario, Canada
Confirm that you know Brian Kierstead: https://www.linkedin.com/e/a7invy-gui8q3jw-35/isd/4773960233/-K10O4AY/?hs=false&tok=07zio-TY-JM4Y1
You are receiving Invitation to Connect emails. Click to unsubscribe: http://www.linkedin.com/e/a7invy-gui8q3jw-35/GcQlk_FnZY4QFKULeN3cDmfp5ofR8Kv66UYR_vTp6rQsvKz65gPRzqo77oBc8imG7TYc_Frp76QlqHh65OygHLdGZWPDFmvA3a3R7sF/goo/reply%2Bi-1563158-da40dced7ba2a078e63e85478a719f1d37075273%40reply%2Egithub%2Ecom/20061/I1659928937_1/?hs=false&tok=3PJ_cGr4qJM4Y1
(c) 2011 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.