ed_is_my_name
ed_is_my_name

Reputation: 631

Rails calling deleted Controller

Basic Rails problem here: I have a controller method named fetch_headlines that I've been trying to debug. I make changes to the controller and they are not reflected in the output. This has made me think that Rails is not properly calling fetch_headlines. Observe the console below.

Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.1-p33), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Started GET "/entries/fetch_headlines" for ::1 at 2020-01-08 16:03:03 -0500
   (0.6ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
  ↳ /Users/ed/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Processing by EntriesController#show as HTML
  Parameters: {"id"=>"fetch_headlines"}
  Rendering entries/show.html.erb within layouts/application
  Rendered entries/show.html.erb within layouts/application (2.8ms)
Completed 200 OK in 482ms (Views: 476.3ms | ActiveRecord: 0.0ms)

Additionally, Rails is presenting the same behavior if I request methods that don't exist such as: qwertyqwerty. I'd expect Rails to throw an error.

Started GET "/entries/qwertyqwerty" for ::1 at 2020-01-09 05:59:13 -0500
Processing by EntriesController#show as HTML
  Parameters: {"id"=>"qwertyqwerty"}
  Rendering entries/show.html.erb within layouts/application
  Rendered entries/show.html.erb within layouts/application (0.6ms)
Completed 200 OK in 18ms (Views: 17.1ms | ActiveRecord: 0.0ms)

Here is my routes.rb

get 'fetch_headlines', to: 'entries#fetch_headlines'
  resources :entries
  resources :keywords
  resources :networks

Thanks.

Upvotes: 0

Views: 34

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

You put get 'fetch_headlines', to: 'entries#fetch_headlines', it creates /fetch_headlines instead of /entries/fetch_headlines route. What you need is rather something like this:

get 'entries/fetch_headlines', to 'entries#fetch_headlines'

or even better

resources :entries do
  collection do
    get :fetch_headlines
  end
end

Upvotes: 3

Related Questions