link_to自定义控制器方法与params

时间:2016-03-10 07:30:34

标签: ruby-on-rails link-to

我正在尝试使用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"}

我是否遗漏了一些盲目明显的东西?

1 个答案:

答案 0 :(得分:1)

似乎有一条路线指向teams/:id中定义的resources :teams,因此您无法将teams/something用作其他路线网址。只需将其更改为其他网址而不是&#39; teams /...'

这将作为一个例子:

get 'team/send_sign_up_instructions', to: 'teams#send_sign_up_instructions', as: :send_sign_up_instructions