2011-11-14 55 views
0

我有一个rails 3.1应用程序,我可以创建邮件爆炸。我有一个邮件列表,用邮件链接发送特定的邮件(使用ajax)。我在自己的Blast控制器中有一个我想要使用的自定义操作。当我点击链接时,它想调用show.js.coffee而不是mail.js.coffee作为前缀。我如何强制它使用我创建的操作。一切正常,当我把一切都在我的控制和show.js.coffee的表演动作,但不是邮件操作和mail.js.coffee等Rails 3.1 javascript文件的使用情况

这是我的高炉局部

<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 

回答

0

我想出了我需要做的事情。这是行得通的。

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

编辑:在我原来的答复,我犹豫要不要在.js.coffee文件使用ERB的。但在进一步的调查,事实证明,Rails的3.1允许这种在其中响应:remote => true表单操作属下的JS的特殊情况。)

我觉得你的问题是

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

尝试在:mail之后加逗号。

+0

Rails解释js.coffee文件中的ruby代码。不再需要erb扩展。我想出了我需要做的事情。这是行得通的。​​<%如果可以? :create,blast%><%= link_to“Mail”,{:action =>:mail,:id => blast.id},:method =>:post,:confirm =>“Are you sure?”,: remote => true%><%end%> – ctilley79

+0

正如你所看到的,我使用上面的注释中的行来修复它 – ctilley79