0
votes

I just started with Rails and devise and I have a task, allow users to sign up only by invitation of existing user. I choose devise-invitable gem and got stuck with a bit unclear documentation. I have this code:

def invitationForm
    @nuser = User.new
end
def invite_user
  @user =  User.invite!({:email => @nuser.email}, current_user)
end

Where invitationForm renders a form:

<%= form_for @nuser, url: {action: "invite_user"} do |f| %>
  <%= f.text_field :email %>
  <%= f.submit "Invite" %>
<% end %>

After all I`m getting this error:

RuntimeError in User#invite

Showing //invite.html.erb where line #2 raised:

Could not find a valid mapping for nil

What am I doing wrong and what should I do?

2

2 Answers

1
votes

I think one of your problems could be here:

<%= form_for @nuser, url: {action: "invite_user"} do |f| %>

Your form was pointing to invite instead of the invite_user method you have created.

0
votes

Okay, the deal was in the setup, somehow. After creating a new project and starting from scratch all workred fine.