Is it a bad practice to name the model "Image" in Rails 4?

In my Rails 4 application, I have a model named Image. The image is not a reserved word in Rails 4, as far as I can tell from the list of reserved words listed here: http://www.rubymagic.org/posts/ruby-and-rails-reserved-words

The problem I am facing is that the routes for the image class create an assistant with a name image_paththat is already an assistant for the images. For example, in order to access the path assistant in one of my unit tests, I need to call Rails.application.routes.url_helpers.image_path(@image), which is easy to forget and difficult for outsiders to debug.

I tend to rename the model to Photo, but first wanted to see if anyone has any other solutions.

+4
source share
1 answer

There is no problem describing your model image, but you will run into some problems with a resource controller named ImagesController, so you will redefine the URLHelpers method image_path.

I think this is not recommended, but you can do it if you want. To solve the problem with routes, you can simply give a different name to your image controller, as shown below:

# config/routes.rb
resource :images, as: :photo # or whatever you want to
+1
source

All Articles