Rails 3.1 javascript 文件使用
我有一个 Rails 3.1 应用程序,可以在其中创建邮件群发。我有一个所有爆炸的列表,其中包含一个用于邮寄特定爆炸的邮件链接(使用ajax)。我的爆炸控制器中有一个我想使用的自定义操作。当我单击链接时,它想要调用 show.js.coffee 而不是 mail.js.coffee 。我如何强制它使用我创建的操作。当我将所有内容放入控制器和 show.js.coffee 的显示操作中,而不是邮件操作和 mail.js.coffee 等时,一切正常。
这是我的blast部分
<td><% if can? :create, Blast%><%= link_to "Mail",blast,:action => :mail :confirm => "Are you sure?",:remote => true%><%end%></td>
这是控制器中的方法
def mail
@customers = Customer.all
@mailcustomers = Customer.where(:opted_out => false)
@blast = Blast.find(params[:id])
end
这是在我的mail.js中.coffee文件
<% @mailcustomers.each do |f|%>
<% BlastMailer.mail_blast(f,@blast).deliver %>
<%end%>
在routes.rb中
resources :blasts do
collection { post :mail }
end
I have a rails 3.1 app where I can create mail blasts. I have a list of all my blasts with a mail link to mail a specific blast (using ajax). I have a custom action in my blasts controller that I want to use. When I click the link it wants to call show.js.coffee instead of mail.js.coffee for ex. how do I force it to use the action I created. Everything works when I put everything in the show action of my controller and show.js.coffee but not the mail action and mail.js.coffee etc.
This is my blast partial
<td><% if can? :create, Blast%><%= link_to "Mail",blast,:action => :mail :confirm => "Are you sure?",:remote => true%><%end%></td>
This is the method in controller
def mail
@customers = Customer.all
@mailcustomers = Customer.where(:opted_out => false)
@blast = Blast.find(params[:id])
end
This is in my mail.js.coffee file
<% @mailcustomers.each do |f|%>
<% BlastMailer.mail_blast(f,@blast).deliver %>
<%end%>
In routes.rb
resources :blasts do
collection { post :mail }
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(编辑:在我最初的回答中,我对在
.js.coffee
文件中使用 ERB 犹豫不决。但经过进一步调查,事实证明 Rails 3.1 允许这样做在特殊情况下,JS 是为了响应:remote => true
表单操作而提供的。)我认为你的问题是
尝试在
:mail。
(Edit: In my original answer, I balked at the use of ERB in a
.js.coffee
file. But on further investigation, it turns out that Rails 3.1 allows this in the special case where the JS is being served in response to a:remote => true
form action.)I think your problem is the
Try putting a comma after
:mail
.我知道我需要做什么。这是有效的线路。
I figured out what I needed to do. This is the line that worked.