Rails 3.1 javascript 文件使用

发布于 2024-12-15 10:33:41 字数 896 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆夏时光 2024-12-22 10:33:41

编辑:在我最初的回答中,我对在 .js.coffee 文件中使用 ERB 犹豫不决。但经过进一步调查,事实证明 Rails 3.1 允许这样做在特殊情况下,JS 是为了响应 :remote => true 表单操作而提供的。)

我认为你的问题是

:action => :mail  :confirm => "Are you sure?"

尝试在 :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

:action => :mail  :confirm => "Are you sure?"

Try putting a comma after :mail.

故乡的云 2024-12-22 10:33:41

我知道我需要做什么。这是有效的线路。

<td>
  <% if can? :create, Blast%>
    <%= link_to "Mail", {:action => :mail, :id=>blast.id}, :method => :post,:confirm => "Are you sure?",:remote => true%>
  <%end%>
</td>

I figured out what I needed to do. This is the line that worked.

<td>
  <% if can? :create, Blast%>
    <%= link_to "Mail", {:action => :mail, :id=>blast.id}, :method => :post,:confirm => "Are you sure?",:remote => true%>
  <%end%>
</td>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文