Search code examples
ruby-on-railsactioncontroller

Rails 2.3.8 application skip controller


I am going to ask a little vague question, but here it goes:

I am maintaining a legacy Rails 2.3.8 application. I noticed a weird behavior, first the application was serving controller_x/action_x without any errors given that there is an app/views/controller_x/action_x.rhtml but there is no definition of action_x in controller_x.rb. Then, after a while it stopped serving it, I had to create action_x empty function in controller_x.rb to make it serve the request again.

What could cause that behavior to happen? How can I serve a view of an action while skipping controller?

Update: The error occurring now is:

ArgumentError in ControllerXController#action_x

no id given

Thanks,


Solution

  • As long as you have the corresponding view file defined (action_x.rhtml), you don't have to define the action (it's good practice to define it though, so that others can easier understand what's going on in your project) in order for the view to be served.

    What error are you getting? How does your routes.rb file look like?

    UPDATE: That action is expecting a parameter so something like this will work: http://localhost:3000/controller_x/action_x/1. Are you sure you only have map.connect ':controller/:action/:id' in your routes file?