Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a rails route that does nothing

I want to discard some requests and to nothing. Generate no errors. Rails 4.1.

A route like this:

ActionController::RoutingError (No route matches [GET] "/edist-images/article/bw_2014-mid-year-outlook_180x120.jpg"):

like image 414
Oz DiGennaro Avatar asked Dec 04 '14 19:12

Oz DiGennaro


People also ask

How do you define a route in Ruby?

We have to define the routes for those actions which are defined as methods in the BookController class. Open routes. rb file in library/config/ directory and edit it with the following content. The routes.

What is RESTful routes in Rails?

The Rails router is responsible for redirecting incoming requests to controller actions. The routing module provides URL rewriting in native Ruby. It recognizes URLs and dispatches them as defined in config/routes.

How do I list a route in Rails?

TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.


1 Answers

You can force Rails to respond to specific routes with a HTTP status code. For example, to respond with a 200 OK for your missing image:

get '/edist-images/article/bw_2014-mid-year-outlook_180x120.jpg', to: proc { [200, {}, ['']] }
like image 107
infused Avatar answered Sep 29 '22 16:09

infused