link_to 带参数的自定义控制器方法
link_to custom controller method with params
我正在尝试使用 link_to
来触发自定义控制器方法。自定义方法用于触发邮件程序。
我的 link_to
在视图中:
<%= link_to 'Resend sign up instructions', send_sign_up_instructions_path(team: @team.name, email: email), class: "button tiny radius" %>
我的路线:
resources :teams
get 'teams/send_sign_up_instructions', to: 'teams#send_sign_up_instructions', as: :send_sign_up_instructions
TeamsController
中的自定义方法:
def send_sign_up_instructions
team_name = params[:team]
email = params[:email]
TeamMailer.notify_signup(team_name, email)
end
错误输出:
{"email"=>"asdfasdfasdfasdf@adsfajsdfakjsdf.com", "team"=>"Some js team", "action"=>"show", "controller"=>"teams", "id"=>"send_sign_up_instructions"}
我是不是遗漏了一些非常明显的东西?
似乎在resources :teams
中定义了一条指向teams/:id
的路由,因此您不能将teams/something
用作另一条路由url。只需将其更改为 url else 而不是 'teams/...'
这将作为示例:
get 'team/send_sign_up_instructions', to: 'teams#send_sign_up_instructions', as: :send_sign_up_instructions
我正在尝试使用 link_to
来触发自定义控制器方法。自定义方法用于触发邮件程序。
我的 link_to
在视图中:
<%= link_to 'Resend sign up instructions', send_sign_up_instructions_path(team: @team.name, email: email), class: "button tiny radius" %>
我的路线:
resources :teams
get 'teams/send_sign_up_instructions', to: 'teams#send_sign_up_instructions', as: :send_sign_up_instructions
TeamsController
中的自定义方法:
def send_sign_up_instructions
team_name = params[:team]
email = params[:email]
TeamMailer.notify_signup(team_name, email)
end
错误输出:
{"email"=>"asdfasdfasdfasdf@adsfajsdfakjsdf.com", "team"=>"Some js team", "action"=>"show", "controller"=>"teams", "id"=>"send_sign_up_instructions"}
我是不是遗漏了一些非常明显的东西?
似乎在resources :teams
中定义了一条指向teams/:id
的路由,因此您不能将teams/something
用作另一条路由url。只需将其更改为 url else 而不是 'teams/...'
这将作为示例:
get 'team/send_sign_up_instructions', to: 'teams#send_sign_up_instructions', as: :send_sign_up_instructions