Query controller using two resources

I have an activation link. I want the user to click on the link, kinda
like this…

domain.com/users/45/activate/1jf872

The number after “users” would be the user id, and the string after
“activate” would be the activation code. In the link above it would be
user id 45 and activation code 1jf872.

I have no problem sending the email. My problem is getting the route
(the url) recognized.

I have this in routes…

resources :users do
member do
get :activate
end
end

users_controller.rb

def activate
@user = User.find(params[:id])
end

Which finds the user. But how can I make the query to find by both the
user id and the activation code?

like select users where users.id = 45 and activation_code = 1jf872

I’m trying to get a url like

/users/45/invitation/ej3j3j (for invitation form, where you enter the
password)

and another
/users/45/activate (for submitting the form)

On 1 August 2011 20:35, Leonel . [email protected] wrote:

I’m trying to get a url like

/users/45/invitation/ej3j3j (for invitation form, where you enter the
password)

You could use /users/45/invitation?activation=ej3j3j
or something similar.

Colin

routes.rb

resources :users do
member do
get :invitation
post :activate
end
end

  1. I go to users/78/invitation (where the form is)
  2. I submit the form and goes to this url users/78/activate
  3. but gives me this error "No route matches “/users/78/activate”

Whyyyyyy?

rake routes

invitation_user GET /users/:id/invitation(.:format)
{:action=>“invitation”, :controller=>“users”}

activate_user POST   /users/:id/activate(.:format) 

{:action=>“activate”, :controller=>“users”}

On Aug 1, 2011, at 2:44 PM, Leonel . wrote:

(the url) recognized.

I have this in routes…

resources :users do
member do
get :activate
end
end

try get ‘:activate/:activation_code’


users_controller.rb

def activate
@user = User.find(params[:id])
end

Along those same lines, try User.find_by_id_and_activation_code(params)

Which finds the user. But how can I make the query to find by both the
user id and the activation code?

like select users where users.id = 45 and activation_code = 1jf872

Walter

Walter D. wrote in post #1014258:

try get ‘:activate/:activation_code’

Along those same lines, try User.find_by_id_and_activation_code(params)

Thanks, but I tried it and I get this error when trying to start the
server…

Exiting
/var/lib/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/routing/mapper.rb:171:in
default_controller_and_action': missing :action (ArgumentError) from /var/lib/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/routing/mapper.rb:72:innormalize_options!’

On Aug 1, 2011, at 4:11 PM, Leonel . wrote:

/var/lib/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/routing/
mapper.rb:171:in
default_controller_and_action': missing :action (ArgumentError) from /var/lib/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/routing/ mapper.rb:72:innormalize_options!’

Try ‘activate/:activation_code’ instead – There wouldn’t be any map
to :activate (the symbol) since it doesn’t exist in your application.
Have a read through the routing guide, too, I may have something
wrong. Try using a match statement rather than get directly. I’m not
sure if this syntax is supported by get.

Walter