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
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>