How do I create another controller action to create an object in rails?
Posted
by Angela
on Stack Overflow
See other posts from Stack Overflow
or by Angela
Published on 2010-05-16T01:41:14Z
Indexed on
2010/05/16
1:50 UTC
Read the original article
Hit count: 190
I have a model called Contact_Email. When an Email template is sent through ActionMailer to a specific Contact, as part of the Create action it sends it through upon .save.
However, I want to create a "skip" action which also creates a Contact_Email, but does NOT send an ActionMailer and allows me to set the status differently.
I want to create a separate action because I want to make this respond to a remote_for_tag so that I can just have an ajax button indicate it has been "skipped":
Here's what I tried, but while it creates a Contact_Email, I end up getting an error when I want to go back and view all the Contacts again.
def skip
@contact_email = ContactEmail.new
@contact_email.contact_id = params[:contact_id]
@contact_email.email_id = params[:email_id]
@contact_email.status = "skipped"
if @contact_email.save
flash[:notice] = "skipped email"
redirect_to contact_emails_url
end
end
© Stack Overflow or respective owner