Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:51:30+00:00 2026-06-07T06:51:30+00:00

I’m currently trying to use a custom method in Rails and I do not

  • 0

I’m currently trying to use a custom method in Rails and I do not know how to do so. Apart from the default methods in the controller, I wanted to add the following:

  def cancel
    @newsletter = Newsletter.find(params[:id])

   respond_to do |format|

  #SendGrid Newsletter API - Delete Newsletter Schedule
  SendGrid.delete_schedule(@newsletter.name)

  @newsletter.status = "CANCELLED"

  @newsletter.save

  format.html { redirect_to newsletters_url }
  format.json { head :no_content }
end

end

The method is just like the default :destroy method but it doesn’t actually destroys the object.

In my view, I had the following:

<% @newsletters.each do |newsletter| %>
  <tr>
    <td><%= newsletter.identity %></td>
    <td><%= newsletter.name %></td>
    <td><%= newsletter.recipients %></td>
    <td><%= newsletter.subject %></td>
    <td><%= newsletter.html %></td>
    <td><%= newsletter.text %></td>
    <td><%= newsletter.schedule %></td>
    <td><%= newsletter.status %></td>
    <td><%= link_to 'Show', newsletter %></td>
    <td><%= link_to 'Edit', edit_newsletter_path(newsletter) %></td>
    <td><%= link_to 'Destroy', newsletter, method: :delete, data: { confirm: 'Are you sure?' } %></td>
    <td><% if newsletter.status == "SCHEDULED" %><%= link_to 'Cancel', newsletter, method: :cancel, data: { confirm: 'Cancel Schedule?' }%><% end %></td>

  </tr>
<% end %>

I got the error: No route matches [POST] “_newsletter url__“

When I rake routes, there isn’t any route for the error above. May I know how to add the route and why is the route needed?


UPDATE
Currently, I still have the no route matches error. Below are all my files related to the ‘Cancel’ method:

routes.rb

  resources :newsletters do
    match '/cancel/:id' => 'newsletters#cancel', :as => :cancel
  end

newsletters_controller.rb

def cancel
@newsletter = Newsletter.find(params[:id])

respond_to do |format|

#SendGrid Newsletter API - Delete Newsletter Schedule
  SendGrid.delete_schedule(@newsletter.name)

  @newsletter.status = "CANCELLED"

  @newsletter.save

  format.html { redirect_to newsletters_path(@newsletter) }
  format.json { head :no_content }
end
end

newsletters/index.html.erb

<%= link_to 'Cancel', newsletter_cancel_path(newsletter) %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:51:33+00:00Added an answer on June 7, 2026 at 6:51 am

    I think you’re mistaking the method: argument in the link_to as corresponding to the method in the controller. Actually it is referring to the RESTful HTTP verb i.e. :post, :delete and :put. So you don’t pass the controller action through this way.

    Instead you can pass in :controller and :action arguments…

    Better still create a route in routes.rb and use the path that rails generates.

    match "/cancel/:id", to: "controller#cancel", as: :cancel
    

    and then the link_to would be something like:

    link_to 'Cancel', cancel_path(newsletter)
    

    Update:
    The error you’re getting is with the redirect_to in your cancel method (in the controller). Change the newsletters_url to newsletter_path(@newsletter) instead.

    If you want to redirect back to the show page for a single newsletter, then you need to do the above (where you pass in the @newsletter parameter), if you want it to go back to the newsletters index page then it’ll be newsletters_path.

    You can check the existence of the routes by typing rake routes in your terminal. You’ll see all the route names there.

    Do you still get an error after changing to redirect_to newsletter_path(@newsletter)?

    The thing that doesn’t quite strike true is that you’re getting a no POST route defined – which usually points to a malformed form_for. Examine your newsletter related forms especially any where you don’t do the regular form_for @newsletter do |f|.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.