Beta Invitation in Rails 3, little problem

INVITATION BETA EMAIL

I have in the email that the app send to friend’s email address

You are invited to ExampleApp.com click below to signup

http://localhost:3000/signup.efweiuvwnjernfwkefwebhsohj


But I have a dot in the url beteween http://localhost:3000 and the token
I wish the following url

http://localhost:3000/signup/efweiuvwnjernfwkefwebhsohj


config/routes.rb

match ‘/signup/:invitation_token’, :to => ‘users#new’

TO HAVE MORE INFORMATION TAKE A LOOK IN THE FOLLOW SCRIPT

#app/models/invitation.rb #how generate the token

class Invitation < ActiveRecord::Base
belongs_to :sender, :class_name => ‘User’
has_one :recipient, :class_name => ‘User’

email_regex = /\A[\w+-.][email protected][a-z\d-.]+.[a-z]+\z/i

validates :recipient_email, :presence => true,
:format => { :with => email_regex }

before_create :generate_token

private

def generate_token
self.token = Digest::SHA1.hexdigest([Time.now, rand].join)
end

end

#/mailers/invitation.text.rb

You are invited to ExampleApp.com click below to signup

<%= @signup_url %>

models/mailer.rb

class Invitation < ActionMailer::Base
default :from => “[email protected]

def invitation(invitation, signup_url)
@signup_url = signup_url
@invitation = invitation
mail(:to => invitation.recipient_email, :subject => “”)

end

/app/controllers/invitations_controller.rb

def create
@invitation = Invitation.new(params[:invitation])

respond_to do |format|
  if @invitation.save
  Mailer.invitation(@invitation,

signup_url(@invitation.token)).deliver
format.html { redirect_to(@invitation, :notice => ‘Invitation
was successfully created.’) }
format.xml { render :xml => @invitation, :status => :created,
:location => @invitation }
redirect_to root_url
else
format.html { render :action => “new” }
format.xml { render :xml => @invitation.errors, :status =>
:unprocessable_entity }
end
end
end

I BELIEVE IS A LITTLE PROBLEM BUT I DON’T UNDERSTAND WHERE IS MY MISTAKE

Thanks for read my post

bye,

C

the problem is here

def create

 redirect_to root_url
 else
   format.html { render :action => "new" }
   format.xml  { render :xml => @invitation.errors, :status =>

:unprocessable_entity }
end
end
end

try it now

Radhames Brito wrote in post #987907:

@invitation = Invitation.new(params[:invitation])

respond_to do |format|
if @invitation.save
Mailer.invitation(@invitation,
signup_url(:invitation_token=>@invitation.token)).deliver
format.html { redirect_to(@invitation, :notice => ‘Invitation
was successfully created.’) }
format.xml { render :xml => @invitation, :status => :created,
:location => @invitation }
redirect_to root_url
else
format.html { render :action => “new” }
format.xml { render :xml => @invitation.errors, :status =>
:unprocessable_entity }
end
end
end

I simply substitute the follow line

Mailer.invitation(@invitation,signup_url(@invitation.token)).deliver

with this

Mailer.invitation(@invitation,signup_url(:invitation_token=>@invitation.token)).deliver

this is the result
http://localhost:3000/signup?invitation_token=30220e3a8db1994bc7c672d55491991f8e2ebf1a

I wish this

http://localhost:3000/signup/30220e3a8db1994bc7c672d55491991f8e2ebf1a

I’m searching in other forum and documentation on line … when I will
find the solution will put here …

bye,

C
ps. I don’t understand 'cause you put the ‘*’ simbol

try this , go to the console and type rails c, then type this

r = ActionController::Routing::Routes

then

r.generate :controller => :invitations, :action => create , :
invitation_token => “123”

see if it generates what you want , then use

Mailer.invitation(@invitation,url_for (:controller => :invitations,
:action
=> create , : invitation_token => @invitation.token,:method =>
:post)).deliver

On Fri, Mar 18, 2011 at 5:01 PM, Cluter V. [email protected]
wrote:

r.generate :controller => :invitations, :action => create , :
invitation_token => “123”

NameError: undefined local variable or method create’ for main:Object
from (irb): 2

it appears that you are launching irb not rails console, to go to the
rails
console you have to type

rails c

at the app directory, then try mixing

r.generate :controller => :invitations, :action => create ,
:invitation_token => “123”

until you get what you want.

Radhames Brito wrote in post #988228:

On Fri, Mar 18, 2011 at 5:01 PM, Cluter V. [email protected]

rails c

at the app directory, then try mixing

r.generate :controller => :invitations, :action => create ,
:invitation_token => “123”

until you get what you want.

I tried same error

NameError: undefined local variable or method create’ for main:Object
from (irb): 2

I believed that the command “rails console” is the
same “rails c” isn`t it?

Radhames Brito wrote in post #988052:

try this , go to the console and type rails c, then type this

r = ActionController::Routing::Routes

then

r.generate :controller => :invitations, :action => create , :
invitation_token => “123”

see if it generates what you want , then use

Mailer.invitation(@invitation,url_for (:controller => :invitations,
:action
=> create , : invitation_token => @invitation.token,:method =>
:post)).deliver

Hey thank you … for your answer the environment of rails c is Rails
3.0.1 and use your advices I receive only an error message after I
insert your follow command:

r.generate :controller => :invitations, :action => create , :
invitation_token => “123”

NameError: undefined local variable or method ´create’ for main:Object
from (irb): 2

Anyway I will use your previous suggest It’s works to accept the
invitation sign up but the signup url is like this:

http://localhost:3000/signup?invitation_token=3022

thank you,

C

Yes it is. but i thought you may have mistakenly used irb instead of
rails c

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs