Receive and send request for the same match

In the routes file I have:

match 'graphs/(:id(/:action))' => 'graphs#(:action)'

and I would like to match this if it is a GET request ( working ) or a POST request ( not working )

I know that I can declare a POST request inside a resource using:

post '/' => :show, :on => :member

But how can I do this to match ?

Thank.

+5
source share
2 answers

if you want both POST and GET

match 'graphs/(:id(/:action))' => 'graphs#(:action)', :via => [:get, :post]

Edit

default values ​​can be set as follows

match 'graphs/(:id(/:action))' => 'graphs#(:action)', :via => [:get, :post],
                                                      :defaults => { :action => "index" }

and the syntax seems correct

+11
source

, HTTP- (GET, POST, PUT, DELETE, PATCH ), , "post", .

match 'graphs/(: id (/: action))' = > 'graphs # (: action)'

post 'graphs/(: id (/: action))' = > 'graphs # (: action)' http POST.

get 'graphs/(: id (/: action))' = > 'graphs # (: action)' Get Get.

http, "via:" .

0

All Articles