【发布时间】:2013-11-30 03:04:12
【问题描述】:
所以,我有一个带有一些学生网格的索引页面。通过一个按钮,我会调用一个电子邮件方法来向@students = Student.all的所有学生发送电子邮件
如何调用方法?
方法的参数是@students,对吗?
<%= link_to 'Email', send_to_student_path(@students) %>
正如我所见here
StudentController.rb
def send_to_student()
#binding.pry
@students.each do |student|
StudentMailer.email_recall(student).deliver
end
end
还有邮递员:
class StudentMailer < ActionMailer::Base
def email_recall(student)
@url = 'http://example.com/login'
mail(to: @student.email,
from: current_user.email,
subject: 'Valid your datas')
end
end
在 routes.rb 我有:
resources :students do
member do
post :send_to_student
end
end
第一个问题: 如何在方法参数中从 @students = Student.all 传递每个学生的 id ?
第二个问题:
如何正确调用send_to_student方法?
在此先感谢
尼古拉斯
【问题讨论】:
-
对不起,我是@students = Student.all
标签: ruby-on-rails email methods parameter-passing params