Button to trigger mailer?

Newbie ActionMailer question:

I've created a mailer, and am pretty sure I've set its parameters correctly.

I've created a view for that mailer, and am also pretty sure I've set it up correctly.

I can call the mailer and it works right when I put the deliver_ in another controller or simply on a page.

So all that's great.

BUT, what I really want to do is have a simple button that, when hit, will trigger that mailer, passing an :id to it as well.

I can't figure out how to code the button though. Any ideas?

here's what's in the mode:

def scheduled(story) recipients story.author.email subject "Your story has been scheduled" from "e-mail@example.com" sent_on Time.now body :story => story end

here's the template (excerpt): Hi <%= @story.author.name %> ....

here's the deliver_ action: Emailer.deliver_scheduled(@story)

Again, all this stuff works but I can't seem to figure out how to simply smack a button and send an e-mail. I'm sure it's something I'm just overlooking.

Thanks!

My god, I think I was massively inarticulate in that previous post. Apologies.

Here's the thing:

I can successfully send an e-mail through all of the above by simply calling it like this:

<%= link_to '<span>send scheduling e-mail</span>', {:action => 'scheduled', :id => story} %>

BUT, after it sends an e-mail, it wants to go to a view called scheduled in the controller it's currently in. Which doesn't exist.

I don't want it to go anywhere. Just send the e-mail, and maybe flash that it sent.

THAT'S my question.

Thanks so much,

Dan

Hi Dan,

My god, I think I was massively inarticulate in that previous post. Apologies.

Happens to us all :wink:

Here's the thing:

I can successfully send an e-mail through all of the above by simply calling it like this:

<%= link_to '<span>send scheduling e-mail</span>', {:action => 'scheduled', :id => story} %>

BUT, after it sends an e-mail, it wants to go to a view called scheduled in the controller it's currently in. Which doesn't exist.

I don't want it to go anywhere. Just send the e-mail, and maybe flash that it sent.

THAT'S my question.

Not sure I completely understand, but try adding:

render :nothing => true

as the last line in your controller method. I think you can add the flash[:message]='blah blah' above that and that it will display, but don't recall having used the two together before myself. Sorry I can't be of more definitive assistance.

HTH, Bill

Use this

<%= link_to_remote '<span>send scheduling e-mail</span>', {:action => 'scheduled', :id => story} %>

and then make a .rjs view to render the part of the page you need...

remember to use the :href attribute and propier view if you want to make it work when js is disabled

Thank you

Rodrigo Dominguez

sinker wrote:

My god, I think I was massively inarticulate in that previous post. Apologies.

Here's the thing:

I can successfully send an e-mail through all of the above by simply calling it like this:

<%= link_to '<span>send scheduling e-mail</span>', {:action => 'scheduled', :id => story} %>

BUT, after it sends an e-mail, it wants to go to a view called scheduled in the controller it's currently in. Which doesn't exist.

I don't want it to go anywhere. Just send the e-mail, and maybe flash that it sent.

THAT'S my question.

Thanks so much,

Dan

You can use

<%= link_to_remote '<span>send scheduling e-mail</span>', {:action => 'scheduled', :id => story} %>

and then in the controller you can update the div of the current page with a ok message or a error message

be sure to use the :href attribute and make a view answer for that action in order to support js disabled

Thanks for the responses!

link_to_remote doesn't seem to do anything. Looking at the terminal window when I hit it, it just reloads the page. I change it back to link_to and the terminal does all the e-mail song & dance. Am I missing a step with link_to_remote?

And render :nothing => true gets rid of the page not found error, but instead simply displays a blank page once the e-mail has been sent.

Hrm...

sinker wrote:

Thanks for the responses!

link_to_remote doesn't seem to do anything. Looking at the terminal window when I hit it, it just reloads the page. I change it back to link_to and the terminal does all the e-mail song & dance. Am I missing a step with link_to_remote?

And render :nothing => true gets rid of the page not found error, but instead simply displays a blank page once the e-mail has been sent.

Hrm...

On Jul 16, 11:57�pm, Rodrigo Dominguez <rails-mailing-l...@andreas-

are you including the js libraries?