views:

34

answers:

1

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

Well, your code seems ok, just a few things.

  • You have no else statement, what if your @contact_email is not saved?

  • You should definately NOT assign all of the params separately. Use a form in the view for contact_email and @contact_email = ContactEmail.new(params[:contact_email]) in controller. Though having "skipped" assigned separately is ok

  • Define you routes correctly. In this case map.resources :contact_emails, :member => {:skip => :post} And everything should be just fine
Tadas Tamosauskas
Ah I think this should be better (but the same) as this: map.skip_email "contact_email/skip_email/:contact_id/:email_id", :controller => "contact_emails", :action => "skip"
Angela