Skip to content

Commit

Permalink
fixing last set of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Avlok Kohli committed Jun 17, 2010
1 parent 0266a18 commit e762300
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Hello <%= @resource.email %>!

Someone has invited you to <%= root_url %>, you can accept it through the link below.

<%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %>
<%= link_to 'Accept invitation', edit_invitation_url(@resource, :invitation_token => @resource.invitation_token) %>

If you don't want to accept the invitation, please ignore this email.
Your account won't be created until you access the link above and set your password.
8 changes: 4 additions & 4 deletions devise_invitable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
"app/controllers/invitations_controller.rb",
"app/views/devise_mailer/invitation.html.erb",
"app/views/invitations/edit.html.erb",
"app/views/invitations/new.html.erb",
"app/controllers/devise/invitations_controller.rb",
"app/views/devise/mailer/invitation.html.erb",
"app/views/devise/invitations/edit.html.erb",
"app/views/devise/invitations/new.html.erb",
"devise_invitable.gemspec",
"init.rb",
"lib/devise_invitable.rb",
Expand Down
8 changes: 5 additions & 3 deletions lib/devise_invitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
mattr_accessor :invite_for
@@invite_for = 0
end

Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation

module DeviseInvitable; end

require 'devise_invitable/controllers/url_helpers'
#require 'devise_invitable/controllers/helpers'
# Had to comment those two lines out and add them to the application initialized

require 'devise_invitable/mailer'
require 'devise_invitable/routes'
require 'devise_invitable/schema'
require 'devise_invitable/rails'
require 'devise_invitable/controllers/url_helpers'
require 'devise_invitable/rails'
36 changes: 20 additions & 16 deletions lib/devise_invitable/controllers/url_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
Devise::Controllers::UrlHelpers.module_eval do
[:path, :url].each do |path_or_url|
[nil, :new_, :accept_].each do |action|
class_eval <<-URL_HELPERS
def #{action}invitation_#{path_or_url}(resource, *args)
resource = case resource
when Symbol, String
resource
when Class
resource.name.underscore
else
resource.class.name.underscore
end
send("#{action}\#{resource}_invitation_#{path_or_url}", *args)
module DeviseInvitable
module Controllers
module UrlHelpers
[:path, :url].each do |path_or_url|
[nil, :new_, :edit_].each do |action|
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{action}invitation_#{path_or_url}(resource, *args)
resource = case resource
when Symbol, String
resource
when Class
resource.name.underscore
else
resource.class.name.underscore
end
send("#{action}\#{resource}_invitation_#{path_or_url}", *args)
end
URL_HELPERS
end
URL_HELPERS
end
end
end
end
4 changes: 2 additions & 2 deletions lib/devise_invitable/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module DeviseInvitable::Mailer
def invitation(record)
setup_mail(record, :invitation)
end

end
end
8 changes: 6 additions & 2 deletions lib/devise_invitable/model.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Devise
module Models

# Invitable is responsible to send emails with invitations.
# When an invitation is sent to an email, an account is created for it.
# An invitation has a link to set the password, as reset password from recoverable.
Expand All @@ -19,6 +18,7 @@ module Models
# User.find(1).accept_invitation! # accept invitation
# User.find(1).resend_invitation! # reset invitation status and send invitation again
module Invitable
extend ActiveSupport::Concern

def self.included(base)
base.class_eval do
Expand All @@ -29,7 +29,7 @@ def self.included(base)
# Accept an invitation by clearing invitation token and confirming it if model
# is confirmable
def accept_invitation!
self.update_attributes(:invitation_token => nil) if self.invited?
self.update_attribute :invitation_token, nil if self.invited?
end

# Verifies whether a user has been invited or not
Expand All @@ -39,6 +39,10 @@ def invited?

# Send invitation by email
def send_invitation
# don't know why token does not get generated unless I add these
generate_invitation_token
save(:validate=>false)

::Devise::Mailer.invitation(self).deliver
end

Expand Down
9 changes: 7 additions & 2 deletions lib/devise_invitable/rails.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
module DeviseInvitable
class Engine < ::Rails::Engine
paths.lib = "lib"

initializer "devise_invitable.add_url_helpers" do |app|
ActionController::Base.send :include, DeviseInvitable::Controllers::UrlHelpers
ActionView::Base.send :include, DeviseInvitable::Controllers::UrlHelpers
end

config.after_initialize do
I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'locales', 'en.yml'))
Devise::Mailer.send :include, DeviseInvitable::Mailer
end

end
end
end

0 comments on commit e762300

Please sign in to comment.