Hamza Ouaghad
Hamza Ouaghad

Reputation: 589

How do I create a new route path to my newly generated action?

I have created a new action in Posts controller, However, it seems that I can not access it.

the action name is 'kill' , so when I type in my browser, localhost:3000/posts/kill

I get the following error : Couldn't find Pad with id=kill

Extracted source (around line #18
def show
    @post_selected = Post.find(params[:id])
    @posts = Post.all
  end

In my routes.rb

resources :posts

match ':controller(:action(/:id))', :via => [:get, :post]
match "/pads/modifier" => "pads#modifier", :via => [:get]

and when I type rake routes , this is what i get

Prefix Verb     URI Pattern                           Controller#Ac
         posts GET      /posts(.:format)                       posts#index
              POST     /posts(.:format)                       posts#create
      new_post GET      /posts/new(.:format)                   posts#new
     edit_post GET      /posts/:id/edit(.:format)              posts#edit
          post GET      /posts/:id(.:format)                   posts#show
              PATCH    /posts/:id(.:format)                   posts#update
              PUT      /posts/:id(.:format)                   posts#update
              DELETE   /posts/:id(.:format)                   posts#destroy
         root GET      /                                     posts#welcome
              GET|POST /:controller(:action(/:id))(.:format) :controller#:

posts_modifier GET      /posts/modifier(.:format)              posts#modifier

How do I generate a path to get my newly created action 'kill'?

========================================================= Update #1 : Solved,

In addition to the answer below, I could make it happen with the following code

resources :posts, controller: 'posts' do 
get 'posts/:action', to: 'posts#:action'
  end

===========================================================

Upvotes: 0

Views: 106

Answers (1)

CWitty
CWitty

Reputation: 4526

get 'posts/kill', to: 'posts#kill'

Upvotes: 1

Related Questions