URLs in mailer view files using namespaces and custom member actions
I am running Ruby on Rails 3 and I would like to use URLs in mailer view files with namespaces and custom member actions. I read this but I have still problems on implementing that.
In routes.rb
I have:
namespace "users" do
resources :accounts do
member do
get 'my_action_name'
post 'my_action_name'
end
end
end
In users_mailer.rb
I have:
class Users::Accounts < ActionMailer::Base
default_url_options[:开发者_开发百科host] = "test_name_site.com"
def account_delete(account)
@account = account
@action_url = users_account_url(:controller => "users/accounts", :action => "my_action_name")
...
end
end
When in the controller I try to do this:
@account = Users::Account.find(params[:id])
Users::Accounts.account_delete(Users::Account.find_by_id(@account.id)).deliver
I get this error:
ActionController::RoutingError (No route matches {:action=>"my_action_name", :controller=>"users/accounts"})
How I can solve that?
In users_mailer.rb
I tryed also
# the difference is: from 'users_account_url' to 'users_accounts_url'
@action_url = users_accounts_url(:controller => "users/account_authentications", :action => "confirm_account_authentication_delete")
# the difference is: from 'users_account_url' to 'url_for'
@action_url = url_for(:controller => "users/account_authentications", :action => "confirm_account_authentication_delete")
but it doesn't work.
You are not specify an ID of a record in users_account_url try this
@action_url = my_action_name_users_account_url(account)
http://0.0.0.0:3000/users/accounts/1/my_action_name
Routing gude
精彩评论