Nested routes not rendering properly in link helper

hey all,

I have this:

scope :path => ‘/activation’, :controller => :activation do
post “create” => :create
get “confirmation” => :confirmation, :as => “confirmation”
get “send_activation_notification”
=> :send_activation_notification, :as => “send_activation” do
resources :users do
resources :accounts
end
end
end

After an activation is created:

def create
if acc_a_usr = @activation.perform
extract_contents acc_a_usr
send_activation_notification @user, @account
render :action => “confirmation”
else
render “new”
end
end

confirmation view loads:

= link_to “Resend Email”, send_activation_path(@user, @account)

That link gets directed to this method (this method gets called in
multiple places so must account for multiple situations):
def send_activation_notification(user=nil, account=nil)
user = user || params[:user]
account = account || params[:account]
CreateAccount.create_account(user, account).deliver
end

Now I look at the url generated by this helper and it’s not right:

send_activation_notification.33?=59

it should be:
send_activation_notification/user/33/account/59 (so that I can access
these ids in the params hash)

I have rea the book “The Rails 3” way and their example of doing what
I want is somehting like this:

resources :actions do
resources :bids
end

In my code I try to mimic something similar:

 get "send_activation_notification"

=> :send_activation_notification, :as => “send_activation” do
resources :users do
resources :accounts
end
end

But it doesn’t work for me. Note that send_activation_notification is
not a restful route, so I couldnt model my code exactly as shown in
the rails book.

thanks for response

This was easy resolution:

send_activation_notification(:user_id => @user.id, :account_id =>
@account.id)

That will pass the params in query string

On Sunday, October 30, 2011 9:31:50 PM UTC-4, John M. wrote:

not a restful route, so I couldnt model my code exactly as shown in
the rails book.

That’s not a valid route at all. I think you might have it backwards.
Check
out the results of “rake routes” if you need to see what all your routes
look like.

Instead of this:

get “send_activation_notification” => :send_activation_notification, :as
=>
“send_activation” do
resources :users do
resources :accounts
end
end

You might want to do something like this:

resources :users do
get ‘send_activation_notification’, :on => :member
resources :accounts
end

Then you will have a send_activation_notification_user route that you
can
use.

thanks for response, the solution I provided also works if you want to
pass params in hash via query string when there isn’t a direct
association between multiple models

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