Update regarding the registrations controller code I posted above - better to put the added code in "new" vs within "build resource':
class Users::RegistrationsController < Devise::RegistrationsController
def new
build_resource({})
resource.invitation_token = params[:invitation_token]
resource.email = resource.invitation.recipient_email if resource.invitation
respond_with self.resource
end
This might be too late for you, but I had this same issue and figured I would post the solution in case it is helpful to someone else out there.
For the Registrations controller, I had to create a "Users" folder in my controllers folder and then put the registrations_controller code below into my new "users/registrations_controller.rb" file (i.e. which inherits from the Devise registrations_controller). To understand why, take a look at the Devise registrations_controller "new" code on Github - essentially, the code that you added into your registrations_controller "new" section needs to be adjusted to use "resource" instead of "@user" and then it needs to run after the resource is built (ie. "build_resource({})"), but before the devise response code (i.e "respond_with self.resource").
For the controllers/users/registrations_controller.rb file:
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def build_resource(hash=nil)
super(hash)
resource.invitation_token = params[:invitation_token]
resource.email = resource.invitation.recipient_email if resource.invitation
end
end
For the routes.rb file:
...
devise_for :users, :controllers => { :registrations => 'users/registrations' }, :action => 'new' do
get 'users/sign_up/:invitation_token' => 'users/registrations#new'
end
...
For the invitation_controller.rb file:
class InvitationsController < ApplicationController
def new
@invitation = Invitation.new
end
def create
@invitation = Invitation.new(params[:invitation])
@invitation.sender = current_user
if @invitation.save
if signed_in?
@invitation.update_attribute(:sent_at, Time.now)
Mailer.invitation(@invitation).deliver
flash[:notice] = "Thank you, your invitation has been sent."
redirect_to new_invitation_url
else
flash[:notice] = "Thank you, we will notify you when we are ready."
redirect_to root_url
end
else
render :action => 'new'
end
end
end
Hi Aaron, Thxs for posting - this is very helpful! However, I can't figure out how to make the arrows only appear for the column which is currently being used for sorting? The code that you posted above seems to add arrows to all of the column titles at the same time. Any input on how to fix this so that an arrow only shows on one column at a time would be greatly appreciated. Thxs in advance!
Update regarding the registrations controller code I posted above - better to put the added code in "new" vs within "build resource':
class Users::RegistrationsController < Devise::RegistrationsController
def new
build_resource({})
resource.invitation_token = params[:invitation_token]
resource.email = resource.invitation.recipient_email if resource.invitation
respond_with self.resource
end
def create
super
end
end
Hi Engin,
This might be too late for you, but I had this same issue and figured I would post the solution in case it is helpful to someone else out there.
For the Registrations controller, I had to create a "Users" folder in my controllers folder and then put the registrations_controller code below into my new "users/registrations_controller.rb" file (i.e. which inherits from the Devise registrations_controller). To understand why, take a look at the Devise registrations_controller "new" code on Github - essentially, the code that you added into your registrations_controller "new" section needs to be adjusted to use "resource" instead of "@user" and then it needs to run after the resource is built (ie. "build_resource({})"), but before the devise response code (i.e "respond_with self.resource").
For the controllers/users/registrations_controller.rb file:
For the routes.rb file:
For the invitation_controller.rb file:
Hi Aaron, Thxs for posting - this is very helpful! However, I can't figure out how to make the arrows only appear for the column which is currently being used for sorting? The code that you posted above seems to add arrows to all of the column titles at the same time. Any input on how to fix this so that an arrow only shows on one column at a time would be greatly appreciated. Thxs in advance!