Code Monkey home page Code Monkey logo

devise_invitable's Introduction

DeviseInvitable

It adds support to Devise for sending invitations by email (it requires to be authenticated) and accept the invitation setting the password.

Requirements

The latest version of DeviseInvitable works with Devise >= 4.6.

If you want to use devise_invitable with earlier Devise releases (4.0 <= x < 4.6), use version 1.7.5.

Installation

Install DeviseInvitable gem:

gem install devise_invitable

Add DeviseInvitable to your Gemfile:

gem 'devise_invitable', '~> 2.0.0'

Automatic installation

Run the following generator to add DeviseInvitable’s configuration option in the Devise configuration file (config/initializers/devise.rb):

rails generate devise_invitable:install

When you are done, you are ready to add DeviseInvitable to any of your Devise models using the following generator:

rails generate devise_invitable MODEL

Replace MODEL by the class name you want to add DeviseInvitable, like User, Admin, etc. This will add the :invitable flag to your model's Devise modules. The generator will also create a migration file (if your ORM supports them).

Manual installation

Follow the walkthrough for Devise and after it's done, follow this walkthrough.

Devise Configuration

Add :invitable to the devise call in your model (we’re assuming here you already have a User model with some Devise modules):

class User < ActiveRecord::Base
  devise :database_authenticatable, :confirmable, :invitable
end

ActiveRecord Migration

Add t.invitable to your Devise model migration:

create_table :users do
  ...
    ## Invitable
    t.string   :invitation_token
    t.datetime :invitation_created_at
    t.datetime :invitation_sent_at
    t.datetime :invitation_accepted_at
    t.integer  :invitation_limit
    t.integer  :invited_by_id
    t.string   :invited_by_type
  ...
end
add_index :users, :invitation_token, unique: true

or for a model that already exists, define a migration to add DeviseInvitable to your model:

def change
    add_column :users, :invitation_token, :string
    add_column :users, :invitation_created_at, :datetime
    add_column :users, :invitation_sent_at, :datetime
    add_column :users, :invitation_accepted_at, :datetime
    add_column :users, :invitation_limit, :integer
    add_column :users, :invited_by_id, :integer
    add_column :users, :invited_by_type, :string
    add_index :users, :invitation_token, unique: true
end

If you previously used devise_invitable with a :limit on :invitation_token, remove it:

def up
  change_column :users, :invitation_token, :string, limit: nil
end

def down
  change_column :users, :invitation_token, :string, limit: 60
end

Mongoid Field Definitions

If you are using Mongoid, define the following fields and indexes within your invitable model:

field :invitation_token, type: String
field :invitation_created_at, type: Time
field :invitation_sent_at, type: Time
field :invitation_accepted_at, type: Time
field :invitation_limit, type: Integer

index( { invitation_token: 1 }, { background: true} )
index( { invitation_by_id: 1 }, { background: true} )

You do not need to define a belongs_to relationship, as DeviseInvitable does this on your behalf:

belongs_to :invited_by, polymorphic: true

Remember to create indexes within the MongoDB database after deploying your changes.

rake db:mongoid:create_indexes

Model configuration

DeviseInvitable adds some new configuration options:

  • invite_for: The period the generated invitation token is valid. After this period, the invited resource won't be able to accept the invitation. When invite_for is 0 (the default), the invitation won't expire.

You can set this configuration option in the Devise initializer as follow:

# ==> Configuration for :invitable
# The period the generated invitation token is valid.
# After this period, the invited resource won't be able to accept the invitation.
# When invite_for is 0 (the default), the invitation won't expire.
# config.invite_for = 2.weeks

or directly as parameters to the devise method:

devise :database_authenticatable, :confirmable, :invitable, invite_for: 2.weeks
  • invitation_limit: The number of invitations users can send. The default value of nil means users can send as many invites as they want, there is no limit for any user, invitation_limit column is not used. A setting of 0 means they can't send invitations. A setting n > 0 means they can send n invitations. You can change invitation_limit column for some users so they can send more or less invitations, even with global invitation_limit = 0.

  • invite_key: The key to be used to check existing users when sending an invitation. You can use multiple keys. This value must be a hash with the invite key as hash keys, and values that respond to the === operator (including procs and regexes). The default value is looking for users by email and validating with Devise.email_regexp.

  • validate_on_invite: force a record to be valid before being actually invited.

  • resend_invitation: resend invitation if user with invited status is invited again. Enabled by default.

  • invited_by_class_name: the class name of the inviting model. If this is nil, polymorphic association is used.

  • invited_by_foreign_key: the foreign key to the inviting model (only used if invited_by_class_name is set, otherwise :invited_by_id)

  • invited_by_counter_cache: the column name used for counter_cache column. If this is nil (default value), the invited_by association is declared without counter_cache.

  • allow_insecure_sign_in_after_accept: automatically sign in the user after they set a password. Enabled by default.

  • require_password_on_accepting: require password when user accepts the invitation. Enabled by default. Disable if you don't want to ask or enforce to set password while accepting, because is set when user is invited or it will be set later.

For more details, see config/initializers/devise.rb (after you invoked the devise_invitable:install generator described above).

Configuring views

All the views are packaged inside the gem. If you'd like to customize the views, invoke the following generator and it will copy all the views to your application:

rails generate devise_invitable:views

You can also use the generator to generate scoped views:

rails generate devise_invitable:views users

Then turn scoped views on in config/initializers/devise.rb:

config.scoped_views = true

Please refer to Devise's README for more information about views.

Configuring controllers

To change the controller's behavior, create a controller that inherits from Devise::InvitationsController. The available methods are: new, create, edit, and update. Refer to the original controllers source before editing any of these actions. Your controller might now look something like this:

class Users::InvitationsController < Devise::InvitationsController
  def update
    if some_condition
      redirect_to root_path
    else
      super
    end
  end
end

Now just tell Devise that you want to use your controller, the controller above is 'users/invitations', so our routes.rb would have this line:

devise_for :users, controllers: { invitations: 'users/invitations' }

be sure that you generate the views and put them into the controller that you generated, so for this example it would be:

rails generate devise_invitable:views users

To change behaviour of inviting or accepting users, you can simply override two methods:

class Users::InvitationsController < Devise::InvitationsController
  private

    # This is called when creating invitation.
    # It should return an instance of resource class.
    def invite_resource
      # skip sending emails on invite
      super { |user| user.skip_invitation = true }
    end

    # This is called when accepting invitation.
    # It should return an instance of resource class.
    def accept_resource
      resource = resource_class.accept_invitation!(update_resource_params)
      # Report accepting invitation to analytics
      Analytics.report('invite.accept', resource.id)
      resource
    end
end

Strong Parameters

When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing DeviseInvitable to handle this concern at the controller as well. Read about it in Devise README

There are just two actions in DeviseInvitable that allows any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permited parameters by default are:

  • invite (Devise::InvitationsController#create) - Permits only the authentication keys (like email)
  • accept_invitation (Devise::InvitationsController#update) - Permits invitation_token plus password and password_confirmation.

Here is an example of the steps needed to add a first_name, last_name and role to invited Users.

Caution: Adding roles requires additional security measures, such as preventing a standard user from inviting an administrator. Implement appropriate access controls to ensure system security.

Configuring your application controller to accept :first_name, :last_name, and :role for a User

Note: These modifications can be applied directly in the InvitationsController if not needed for other Devise actions.

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  # Permit the new params here.
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:invite, keys: [:first_name, :last_name, :role])
  end

Define your roles in the User model

class User < ApplicationRecord
  has_many :models

  enum role: {Role 1 Name: 0, Role 2 Name: 1, Role 3 Name: 2, etc...}
end

In the Invitation view

<h2><%= t "devise.invitations.new.header" %></h2>

<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>
  <% resource.class.invite_key_fields.each do |field| -%>
    <div class="field">
      <%= f.label field %><br />
      <%= f.text_field field %>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :first_name %>
    <%= f.text_field :first_name %>
  </div>

  <div class="field">
    <%= f.label :last_name %>
    <%= f.text_field :last_name %>
  </div>

  <div class="field">
    <%= f.label :role %>
    <%= f.select :role, options_for_select(User.roles.map { |key, value| [key.humanize, key] }), {prompt: "Select Role"} %>
  </div>

  <div class="actions">
    <%= f.submit t("devise.invitations.new.submit_button") %>
  </div>
<% end %>

Usage

Send an invitation

To send an invitation to a user, use the invite! class method. Note: This will create a user, and send an email for the invite. :email must be present in the parameters hash. You can also include other attributes in the hash. The record will not be validated.

User.invite!(email: '[email protected]', name: 'John Doe')
# => an invitation email will be sent to [email protected]

If you want to create the invitation but not send it, you can set skip_invitation to true.

user = User.invite!(email: '[email protected]', name: 'John Doe') do |u|
  u.skip_invitation = true
end
# => the record will be created, but the invitation email will not be sent

When generating the accept_user_invitation_url yourself, you must use the raw_invitation_token. This value is temporarily available when you invite a user and will be decrypted when received.

accept_user_invitation_url(invitation_token: user.raw_invitation_token)

When skip_invitation is used, you must also then set the invitation_sent_at field when the user is sent their token. Failure to do so will yield "Invalid invitation token" error when the user attempts to accept the invite. You can set the column, or call deliver_invitation to send the invitation and set the column:

user.deliver_invitation

You can add :skip_invitation to attributes hash if skip_invitation is added to attr_accessible.

User.invite!(email: '[email protected]', name: 'John Doe', skip_invitation: true)
# => the record will be created, but the invitation email will not be sent

skip_invitation skips sending the email, but sets invitation_token, so invited_to_sign_up? on the resulting user returns true.

To check if a particular user is created by invitation, irrespective to state of invitation one can use created_by_invite?

Warning

When using skip_invitation you must send the email with the user object instance that generated the tokens, as user.raw_invitation_token is available only to the instance and is not persisted in the database.

You can also set invited_by when using the invite! class method:

User.invite!({ email: '[email protected]' }, current_user) # current_user will be set as invited_by

Sending an invitation after user creation

You can send an invitation to an existing user if your workflow creates them separately:

user = User.find(42)
user.invite!(current_user)  # current user is optional to set the invited_by attribute

Find by invitation token

To find by invitation token use the find_by_invitation_token class method.

user = User.find_by_invitation_token(params[:invitation_token], true)

Accept an invitation

To accept an invitation with a token use the accept_invitation! class method. :invitation_token must be present in the parameters hash. You can also include other attributes in the hash.

User.accept_invitation!(invitation_token: params[:invitation_token], password: 'ad97nwj3o2', name: 'John Doe')

Callbacks

A callback event is fired before and after an invitation is created (User#invite!) or accepted (User#accept_invitation!). For example, in your resource model you can add:

# Note: callbacks should be placed after devise: :invitable is specified.
before_invitation_created :email_admins
after_invitation_accepted :email_invited_by

def email_admins
  # ...
end

def email_invited_by
  # ...
end

The callbacks support all options and arguments available to the standard callbacks provided by ActiveRecord.

Scopes

A pair of scopes to find those users that have accepted, and those that have not accepted, invitations are defined:

User.invitation_accepted     # => returns all Users for whom the invitation_accepted_at attribute is not nil
User.invitation_not_accepted # => returns all Users for whom the invitation_accepted_at attribute is nil
User.created_by_invite       # => returns all Users who are created by invitations, irrespective to invitation status

Integration in a Rails application

Since the invitations controller takes care of all the creation/acceptation of an invitation, in most cases you wouldn't call the invite! and accept_invitation! methods directly. Instead, in your views, put a link to new_user_invitation_path or new_invitation_path(:user) or even /users/invitation/new to prepare and send an invitation (to a user in this example).

After an invitation is created and sent, the inviter will be redirected to after_invite_path_for(inviter, invitee), which is the same path as signed_in_root_path by default.

After an invitation is accepted, the invitee will be redirected to after_accept_path_for(resource), which is the same path as signed_in_root_path by default. If you want to override the path, override invitations controller and define after_accept_path_for method. This is useful in the common case that a user is invited to a specific location in your application. More on Devise's README, "Controller filters and helpers" section.

The invitation email includes a link to accept the invitation that looks like this: /users/invitation/accept?invitation_token=abcd123. When clicked, the invited must set a password in order to accept its invitation. Note that if the invitation_token is not present or not valid, the invited is redirected to invalid_token_path_for(resource_name), which by default is after_sign_out_path_for(resource_name).

The controller sets the invited_by_id attribute for the new user to the current user. This will let you easily keep track of who invited whom.

Controller filter

InvitationsController uses authenticate_inviter! filter to restrict who can send invitations. You can override this method in your ApplicationController.

Default behavior requires authentication of the same resource as the invited one. For example, if your model User is invitable, it will allow all authenticated users to send invitations to other users.

You would have a User model which is configured as invitable and an Admin model which is not. If you want to allow only admins to send invitations, simply overwrite the authenticate_inviter! method as follow:

class ApplicationController < ActionController::Base
  protected

    def authenticate_inviter!
      authenticate_admin!(force: true)
    end
end

And include DeviseInvitable::Inviter module into Admin model:

class Admin < ActiveRecord::Base
  devise :database_authenticatable, :validatable
  include DeviseInvitable::Inviter
end

Has many invitations

If you want to get all records invited by a resource, you should define has_many association in the model allowed to send invitations.

For the default behavior, define it like this:

has_many :invitations, class_name: self.to_s, as: :invited_by

For the previous example, where admins send invitations to users, define it like this:

has_many :invitations, class_name: 'User', as: :invited_by

I18n

DeviseInvitable uses flash messages with I18n with the flash keys :send_instructions, :invitation_token_invalid and :updated. To customize your app, you can modify the generated locale file:

en:
  devise:
    invitations:
      send_instructions: 'An invitation email has been sent to %{email}.'
      invitation_token_invalid: 'The invitation token provided is not valid!'
      updated: 'Your password was set successfully. You are now signed in.'
      updated_not_active: 'Your password was set successfully.'

You can also create distinct messages based on the resource you've configured using the singular name given in routes:

en:
  devise:
    invitations:
      user:
        send_instructions: 'A new user invitation has been sent to %{email}.'
        invitation_token_invalid: 'Your invitation token is not valid!'
        updated: 'Welcome on board! You are now signed in.'
        updated_not_active: 'Welcome on board! Sign in to continue.'

The DeviseInvitable mailer uses the same pattern as Devise to create mail subject messages:

en:
  devise:
    mailer:
      invitation_instructions:
        subject: 'You got an invitation!'
        user_subject: 'You got a user invitation!'

Take a look at the generated locale file to check all available messages.

Check out wiki for translations.

Use with sub schema

If you are using sub schema in you application, you need to make sure that you are prioritizing your sub schema scheme over Warden in Rack. For instance, if you are using the Apartment gem go inside your config/application.rb file, add the following lines:

module YourSite
  class Application < Rails::Application
    ...
    Rails.application.config.middleware.insert_before Warden::Manager, Apartment::Elevators::Subdomain
  end
end

Other ORMs

DeviseInvitable supports ActiveRecord and Mongoid, like Devise.

Wiki

It's possible to find additional information about DeviseInvitable on the Wiki:

https://github.com/scambra/devise_invitable/wiki

Testing

To run tests:

bundle install
bundle exec rake test

Contributors

Check them all at:

https://github.com/scambra/devise_invitable/contributors

Special thanks to rymai for the Rails 3 support, his fork was a great help.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2019 Sergio Cambra. See LICENSE for details.

devise_invitable's People

Contributors

aderyabin avatar azdaroth avatar bradleypriest avatar cambridgemike avatar damienlethiec avatar dependabot[bot] avatar empact avatar guillewu avatar harrikauhanen avatar jdewyea avatar jivdhaliwal avatar jkraemer avatar jmstfv avatar josepjaume avatar jsmestad avatar lunks avatar masterlambaster avatar niclas avatar nurey avatar pelle avatar petergoldstein avatar rhymes avatar rlue avatar scambra avatar sdepold avatar seballot avatar swrobel avatar thbishop avatar yshmarov avatar zoras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

devise_invitable's Issues

undefined method `invitation_instructions' for Devise::Mailer:Class

Hi

On Rails 3.0.1, with Gemfile:

...
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
gem 'devise_invitable', :git => 'git://github.com/scambra/devise_invitable.git'
...

When I fill in the invitation form and hit the submit button, I get the backtrace listed below. It appears that the Devise::Mailer has "unincluded" DeviseInvitable::Mailer. If I check the Devise::Mailer ancestors at startup, I can see DeviseInvitable::Mailer. When I get around the calling invitation_instructions, it is no longer in the ancestors. I'm pretty inexperience with ruby & rails so I guess it's possible I'm doing something stupid, but I can't see where. I'm not interacting with the Devise::Mailer anywhere in my project code, as far as I can see.

vendor/bundle/ruby/1.9.1/gems/actionmailer-3.0.1/lib/action_mailer/deprecated_api.rb:74:in `method_missing'
vendor/bundle/ruby/1.9.1/gems/actionmailer-3.0.1/lib/action_mailer/base.rb:427:in `method_missing'
vendor/bundle/ruby/1.9.1/bundler/gems/devise_invitable-f1a3a79b94e2/lib/devise_invitable/model.rb:59:in `invite!'
vendor/bundle/ruby/1.9.1/bundler/gems/devise_invitable-f1a3a79b94e2/lib/devise_invitable/model.rb:116:in `invite!'
vendor/bundle/ruby/1.9.1/bundler/gems/devise_invitable-f1a3a79b94e2/app/controllers/devise/invitations_controller.rb:16:in `create'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/abstract_controller/base.rb:150:in `process_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/rendering.rb:11:in `process_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:450:in `_run__330477678__process_action__446329792__callbacks'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:93:in `run_callbacks'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/abstract_controller/callbacks.rb:17:in `process_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/notifications.rb:52:in `block in instrument'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/notifications.rb:52:in `instrument'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/rescue.rb:17:in `process_action'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:34:in `block in process_action'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:252:in `block in perform_action_with_newrelic_trace'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/agent/method_tracer.rb:141:in `trace_execution_scoped'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:247:in `perform_action_with_newrelic_trace'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:33:in `process_action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/abstract_controller/base.rb:119:in `process'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/abstract_controller/rendering.rb:40:in `process'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal.rb:133:in `dispatch'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_controller/metal.rb:173:in `block in action'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/routing/route_set.rb:62:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/routing/route_set.rb:27:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/routing/mapper.rb:34:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:148:in `block in call'
vendor/bundle/ruby/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:93:in `block in recognize'
vendor/bundle/ruby/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:75:in `optimized_each'
vendor/bundle/ruby/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:92:in `recognize'
vendor/bundle/ruby/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:139:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/routing/route_set.rb:492:in `call'
vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-2.13.3/lib/new_relic/rack/developer_mode.rb:20:in `call'
vendor/bundle/ruby/1.9.1/gems/hoptoad_notifier-2.3.12/lib/hoptoad_notifier/rack.rb:27:in `call'
vendor/bundle/ruby/1.9.1/gems/haml-3.0.23/lib/sass/plugin/rack.rb:41:in `call'
vendor/bundle/ruby/1.9.1/gems/warden-1.0.1/lib/warden/manager.rb:35:in `block in call'
vendor/bundle/ruby/1.9.1/gems/warden-1.0.1/lib/warden/manager.rb:34:in `catch'
vendor/bundle/ruby/1.9.1/gems/warden-1.0.1/lib/warden/manager.rb:34:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/head.rb:14:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/methodoverride.rb:24:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/flash.rb:182:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/cookies.rb:287:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/callbacks.rb:44:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/sendfile.rb:107:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/rack/logger.rb:13:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/lock.rb:11:in `block in call'
:10:in `synchronize'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/lock.rb:11:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/static.rb:30:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/application.rb:168:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/application.rb:77:in `method_missing'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/rack/log_tailer.rb:14:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/content_length.rb:13:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/chunked.rb:15:in `call'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:76:in `block in pre_process'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:74:in `catch'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:74:in `pre_process'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:57:in `process'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:42:in `receive_data'
vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in `start'
vendor/bundle/ruby/1.9.1/gems/thin-1.2.7/lib/thin/server.rb:156:in `start'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/handler/thin.rb:14:in `run'
vendor/bundle/ruby/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/commands/server.rb:65:in `start'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/commands.rb:30:in `block in '
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/commands.rb:27:in `tap'
vendor/bundle/ruby/1.9.1/gems/railties-3.0.1/lib/rails/commands.rb:27:in `'
script/rails:6:in `require'
script/rails:6:in `'

Also: if I stop and start Thin, then refresh the web page currently showing the backtrace (http://0.0.0.0:3000/users/invitation), then the invitation works and the email is sent with the correct instructions inside. So it looks like everything is loaded correctly on the first request, but subsequent requests use a "redefined" Devise::Mailer.

Any ideas?

Cheers
Lee

devise git and dependencies

Hello,
sorry for creating a ticket about this, however:

gem "devise", :git => "git://github.com/plataformatec/devise.git"
gem "devise_invitable", :git => "git://github.com/scambra/devise_invitable.git"

Could not find gem 'devise (~> 1.1.0)', required by 'devise_invitable', in any of the sources

If it is compatible with devise git can we get a dependencies update?
Thanks!

error mongoid not found

I installed invitable and tried to to my User Devise model ... but got an error :

Updating .gem files in vendor/cache

  • devise_invitable-0.4.rc.gem
    Your bundle is updated! Use bundle show [gemname] to see where a bundled gem is installed.
    rubydev:videoseve (ruby-1.9.2@rails3)$ rails generate devise_invitable:install
    insert config/initializers/devise.rb
    create config/locales/devise_invitable.en.yml
    rubydev:videoseve (ruby-1.9.2@rails3)$ rails generate devise_invitable User
    insert app/models/user.rb
    error mongoid [not found]

I can add manually :invitable to User , and when creating a user from the console, I can see the record fields : invitation_token: nil, invitation_sent_at: nil
so it seems ok, but why the : error mongoid [not found] ???

overriding authenticate_inviter! doesn't seem to work

Hi,

Odd problem for me:

I need to override the authenticate_inviter! method, so per readme instructions I add to my application_controller:

def authenticate_inviter!
false # setting it false just test, will be changed to: current_user.role? :admin
end

In my understanding the override above should prevent any invitations being created. However, they still get send and saved to the db as normal.

What am I missing?

Thanks for your time,
Erwin

Could not find generator devise_invitable:install

Not only that but also...
rails generate devise_invitable User
Could not find generator devise_invitable.

This is on rails 3.0.0 and the following from gemfile.lock
devise (1.1.2)
bcrypt-ruby (> 2.1.2)
warden (
> 0.10.7)
devise_invitable (0.3.2)
devise (~> 1.1.0)

It was installed with "gem install devise_invitable" and also "bundle install". rails generate shows neither devise_invitable nor devise_invitable:install as available tasks. devise_invitable:views is available and generates the templates.

Customize the Redirect after Accepting an Invite

Hello, after a user accepts an invitation and signs up the flash notice "Your password was set successfully. You are now signed in." appears.

How can you customize that msg and redirect to a different URL, I would like to redirect to /gettingstarted

thanks

Add invited_by :user

When I send an invite I´d like something like this to happen:

new_user.invited_by = current_user

An Admin can create new users. Later on I´d like to restrict what the user can access trought which admin invited him.

deliver_invitation removed from devise_invitable

Delivering invitation mail is now directly invoked from invite! however earlier there was a method called deliver_invitation for it.

I needed to queue the emails in the background and send later using delayed_jobs. I worked around it be overriding the invite! in my project, but if deliver_invitation was still around it could have been done in a better way.

Please excuse my poor English.

losing token on validation error.

I noticed an issue when setting a bad password (ie too short)... it catches the error perfectly but on redirect the user back to the form the token is lost from the form and is no longer able to register unless they go back to the email.

Invited Users - Then trying to SignIn or Register

My app is experiencing a UX issue when invited users at some point after being invited try to sign in or register. Devise currently does not notify the user they need to click the invitation link sent via email. Devise outputs a very unhelpful msg along the lines of "user not found etc..."

Has anyone else experienced this? Any thoughts around, whenever an invited user tries to Register, Sign In or Reset their password, devise forwards them to a screen letting the user know they've been invited and gives the user the option to resend the invitation link to access the site?

Thoughts? Thanks!

generator crashes with uninitialized constant DeviseMailer

I just added the gem to my Gemfile now (Rails 3.0.3). I ran bundle install and then rails generate devise_invitable:install. I see:

/Users/james/.rvm/gems/ruby-1.9.2-p0/gems/devise_invitable-0.1.3/lib/devise_invitable.rb:4: warning: class variable access from toplevel
/Users/james/.rvm/gems/ruby-1.9.2-p0/gems/devise_invitable-0.1.3/lib/devise_invitable/mailer.rb:9:in `<top (required)>': uninitialized constant DeviseMailer (NameError)
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/devise_invitable-0.1.3/lib/devise_invitable.rb:11:in `<top (required)>'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `block (2 levels) in require'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `block in require'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
        from /Users/james/Sites/code/rails/mtales.com/config/application.rb:7:in `<top (required)>'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:15:in `require'
        from /Users/james/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:15:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

Accepting invitation with extra fields

I have a user model with extra fields like first_name and last_name. When a user is invited, the inviter can specify their first_name and last_name. When I follow the token from the email, none of the fields on the form are pre-populated with these columns. If I create an inherited InvitationsController and copy exactly what's in the Devise::InvitationsController, the fields are now pre-populated correctly. I have this as a work around but is this intended or is the invitations only purpose is to specify a password and confirmation? I don't like overriding your default behavior because it just creates more work in the future. Thanks for the help.

def edit
if params[:invitation_token] && self.resource = resource_class.first(:conditions => { :invitation_token => params[:invitation_token] })
render_with_scope :edit
else
set_flash_message(:alert, :invitation_token_invalid)
redirect_to after_sign_out_path_for(resource_name)
end
end

Sent invitations list

It will be nice to add ability to see all sent by user invitations with status - accepted or not accepted

Overriding Invitations Controller

Is it possible to override the InvitationsController?

I would like my DEF CREATE to respond back with JS: Something like:

def create
self.resource = resource_class.invite!(params[resource_name])

if resource.errors.empty?
  #set_flash_message :notice, :send_instructions
  render :js => "alert('Hello Rails');"
end

Is this possible without having to fork?

Getting Started

Hello, I'm creating a Getting Started wizard and would like to have a page for Invitations where users can enter a CSV of emails. Has anyone done this before?

How can I include the /devise/invitations/new form in my GettingStarted Controller. I tried:

            <%= render 'devise/invitations/new' %>

Which errors with: <%= render 'devise/invitations/new' %>

Thanks for any tips.

uninitialized constant Devise::Mailer

I'm getting this with Rails 2.3.8

$ script/console
Loading development environment (Rails 2.3.8)
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant':NameError: uninitialized constant Devise::Mailer

%{email} in i18n not work

Please, help me resolve problem with i18n and %{email}

missing interpolation argument in "invite to %{email}" ({:resource_name=>:user} given)

Set attributes that aren't mass assignable on invitation?

Hi,

I would like to set some roles for the people I invite. However, the roles attribute is not mass-assignable (for obvious security reasons). The attribute can be set by using "user.roles=".

How would I go about getting invitable to assign this attribute for me? I tried overriding the invitations#create, but didn't get that to work.

Could you point me in the right direction.

Thanks for your time,
Erwin

Email has already been taken

while I'm loving this gem I've run into one big blocker, "Email has already been taken" If a user is invited and then tries to register on their own (which is common) the unregistered/invited user can't join and receives a "Email has already been taken" error on SignUp. Very problematic.

Is there any way to handle this as is today?

My suggestion would be, that a invited used if they then try to register for an invitation that was never accepted be allowed to register. And that it either overwrite or delete their old invitation after all the paramaters are checked to be valid.

Thoughts?

password_salt is no longer created by devise 1.2.rc

It seems that the Git version of devise no longer creates the password_salt field, which is making the installation of devise_invitable fail when running the migration. All that seems to be needed is to remove the line that changes the password_salt column, or at least making it run only when the column exists to begin with.

Invitation token is invalid

When you invite someone, click the invite link, register. Everything works fine..

If you then click that same used invite link again, it takes you to the /users/invitations signup page, giving the impression that you can join or overwrite your last signup. When you submit it does fail with the "Invitation token is invalid" which is good.

But I a better UX would probably be when clicking the invite link, if the token is invalid, redirect to the root with a flash message "Your invitation has expired .... "

warning: class variable access from toplevel

i get this everytime i login to console or start the server rails s...

/Users/myname/.rvm/gems/ruby-1.9.2-rc2/gems/devise_invitable-0.3.1/lib/devise_invitable.rb:8: warning: class variable access from toplevel

Limit number of invitations

Could you add the ability to set the number of invites a user gets, by default.

I guess you would add an invitation_limit column to the resource table then in the Devise config file add a config.invitation_limit, where the number is how many invitations the user has left. Default is nil (meaning no limit). Then, if the config.invitation_limit is set to a number other than nil, the number would decrease every time the user sends an invitation.

I would fork and build that myself, but it is a tad beyond my abilities at this point.

set_flash_message API has changed

It look like they updated jose updated the set_flash_message API back in July
heartcombo/devise@0aa41d6#diff-3

Thanks for this gem, saved me some time!

Out of the box, the Invitaions#create is trying to send a (now missing) 3rd param
https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb#L19

Was gonna plug this one up myself, but I can't get the test to run. All I did was add set_flash_message as a private method in my invitation controller to beat out devise's. Not clean - maybe you can integrate it better.

Help with delayed job

Can you please point me to an example of how to implement delayed_job with devise_invitable? I cannot figure out where to call handle_asynchronously :invite!.

Thanks!

Moving views into views/devise folder

Views are not recognized in app/views/devise/invitations/, they only work in app/views/users/invitations and such. It would be more comfortable to nest this into devise folder in views.

No route matches "/users/invitation/accept"

I just setup a new rails project and tried sending the invite using rails console. Invitation mail got successfully delivered to my mailbox, but on clicking the link to accept invitation I get the no route error. I googled it but didn't find anything useful, so may be I am doing something wrong. Can you please help me?

I am using Rails 3.0.4, Devise 1.1.5, devise_invitable 0.3.5 and MongoID 2.0.0.rc7

Thanks

User.invite! skips all validations

In the invite! class method, the record is saved skipping all validations. It looks like this is needed to avoid the password-required validation problem, but it seems like throwing the baby out with the bathwater as we say in England : )

In my case I've lost my checks for a well formatted email address, check that the User#role is given, etc.

NoMethodError (undefined method `invitation' for Devise::Mailer:Class)

This is with devise 1.1.7 and devise_invitable 0.3.6. I'm getting a "NoMethodError (undefined method `invitation' for Devise::Mailer:Class)" in development mode when trying to invite someone. The trace goes like this:

undefined method `invitation' for Devise::Mailer:Class
actionmailer (3.0.5) lib/action_mailer/deprecated_api.rb:74:in `method_missing'
actionmailer (3.0.5) lib/action_mailer/base.rb:429:in `method_missing'
devise_invitable (0.3.6) lib/devise_invitable/model.rb:39:in `send_invitation'
devise_invitable (0.3.6) lib/devise_invitable/model.rb:48:in `invite!'
devise_invitable (0.3.6) lib/devise_invitable/model.rb:116:in `invite!'
app/controllers/adm/admins_controller.rb:12:in `create'

app/controllers/adm/admins_controller.rb:12: Admin.invite!(params[:admin])

I'm pretty lost why this is happening in development only, test and production env are working fine!?

Sample Code

Can you provide a little code snippet in the README that shows how you create and send an Invitation? The instructions on how to add to an existing project are great.

validate_on_invite implementation

Are you planning on including this in the next release because when you embed a form into another controller it would be ideal to implement for that situation. Thanks!

undefined method `invitation_instructions' for Devise::Mailer:Class

Morning all,

I am using Rails 3.0.5, with the following devise related gems:

gem 'devise', '1.2.rc'
gem 'devise_invitable', '0.4.rc4'

When I submit the form to invite the new user, I have the following error

undefined method `invitation_instructions' for Devise::Mailer:Class

Just to clarify, I have do have the following file in my views/devise/mailer:

invitation_instructions.html.haml

And this is my Full Trace:

actionmailer (3.0.5) lib/action_mailer/deprecated_api.rb:74:in `method_missing'
actionmailer (3.0.5) lib/action_mailer/base.rb:429:in `method_missing'
devise_invitable (0.4.rc4) lib/devise_invitable/model.rb:87:in `deliver_invitation'
devise_invitable (0.4.rc4) lib/devise_invitable/model.rb:62:in `invite!'
devise_invitable (0.4.rc4) lib/devise_invitable/model.rb:141:in `invite!'
devise_invitable (0.4.rc4) app/controllers/devise/invitations_controller.rb:17:in `create'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:450:in `_run__1118674731856297132__process_action__2368427774484213763__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:27:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/mapper.rb:39:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call'
warden (1.0.3) lib/warden/manager.rb:35:in `block in call'
warden (1.0.3) lib/warden/manager.rb:34:in `catch'
warden (1.0.3) lib/warden/manager.rb:34:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.2) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.2) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.2) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.2) lib/rack/lock.rb:11:in `block in call'
:10:in `synchronize'
rack (1.2.2) lib/rack/lock.rb:11:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.2) lib/rack/content_length.rb:13:in `call'
rack (1.2.2) lib/rack/handler/webrick.rb:52:in `service'
/Users/Daren/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/Daren/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/Daren/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Any help would be very much appreciated!

Cheers,

D.

Model.invite! locks database on cucumber

I am using cucumber with webrat and:

In one step (Step 1), I call User.invite!. Just after this, other step runs (Step 2) trying to create an User (in fact, I am using machinist. So, it is calling User.make!).

BUT, Step 2 is not really creating the User (it raises no error, just create a user, set id, etc. but it is not really saved at DB).

If I run Step 2 before Step 1, everything goes ok, ponies and rainbows!

Will investigate more about it. Any ideas about what can be happening?

Does Invitable need a Invitations Class

When an Invitation is created I want to record:
who created it: created_by
optional message: message

Therefore I'm thinking I need to generate a Invitation model with these fiends because it seems sloppy to add more fields to the users table.

So what I could use your help with is, how do I create the controller that allows me to set the invitation and record these additional fields?

Thanks

Information about inviter should be available

When we send an invitation, it seems that the code is unaware of the inviter.

I suggest that the user model have a virtual attribute called "inviter" which has the "current_user" available in it. The invite! method called in InvitationController's should provide an another parameter "current_user". This would be assigned to the virtual attribute inviter in the user model. This way the mailer view can also get hold of the inviter.

I'll try sending in a patch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.