Lannister Lannister - 6 months ago 17
Ruby Question

when does rails make path with a dot rather than backslash?

why rails is making a path like

/notification_templates/duplicate_me.1


it is supposed to be

/notification_templates/duplicate_me/1


my routes are

resources :notification_templates do
collection do
get :blast_send
patch :deactivate
patch :activate
get :get_list
post :duplicate_me
end
end


and my link is
<%= link_to "Duplicate", duplicate_me_notification_templates_path(template), method: :post, class: "btn btn-primary" %>

Answer

Since the route is made for collection, it does not expect a template instance variable for id.

To make the route as /notification_templates/duplicate_me/1, make the changes in your routes.rb like

resources :notification_templates do
  collection do
    get :blast_send
    patch :deactivate
    patch :activate
    get :get_list
  end
  post :duplicate_me, on: :member
end

and change your view to

<%= link_to "Duplicate", duplicate_me_notification_template_path(template), method: :post, class: "btn btn-primary" %>
Comments