Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError in MembersController#create undefined method `role_ids' for nil:NilClass #25

Open
michaelward82 opened this issue Sep 4, 2011 · 4 comments

Comments

@michaelward82
Copy link

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?

@rbriank
Copy link
Owner

rbriank commented Sep 4, 2011

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 <
reply@reply.github.com>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 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?

Reply to this email directly or view it on GitHub:
#25

@michaelward82
Copy link
Author

In rails console:

Load the user that was created by membership registration

> current_user = User.last
 => #<User id: 15, username: "email@example.com", email: "email@example.com", 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.

@michaelward82
Copy link
Author

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

@rbriank
Copy link
Owner

rbriank commented Nov 2, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants