1. Inefficient practice to leave unused REST actions?
As far as I can answer this. If you do not need an index action for the controller, you do not have it, period. But what you should exclude this action in your routes, for example. by making resource :resources, :except => [:index]
. This can be useful when you save from errors because NoTemplateError is not the same as RoutingError (which means you can skip something in production).
It is also a good development assistant. When you accidentally write a link to the index of an unused controller, you will receive an error message on the page containing the link if you excluded the action on your routes. If you do not, you will see an error message after clicking the link, because the route is valid (but does not have a function / template / in general).
2. Does the above script make it as if I am doing it right? what I wanted it to be in home index # to list all resources, not # index resources?
I cannot answer this question without understanding your business logic / application workflow. But if you do not need it, you will leave it.
If this is a cosmetic issue (for example, the # resource index is mostly needed, but under a different URL), you can simply create a match "home", :to => "resources#index"
route match "home", :to => "resources#index"
. This will reduce your user home controller, and you can use the index action on resources
, which will be available in /home
and under /resources
. But then again, this may not be the best option for your workflow / logic, so this is just a suggestion.
3. If this is bad practice, how can I create them manually?
There is a great page on the Rails page about all your routing needs. Look over there.
4. What if I want to change the default URL?
Rails are a conditional configuration. Means that these methods are rails. Itβs good to adhere to this agreement, so every time you return to your application, change things, you know, at least, how it works because of this agreement. Even rail encoders that don't know your application can make changes to it faster when everyone adheres to this agreement. This interesting commercial offer by RoR vs PHP explains it very well.
You can change them, but you should not.
5. Given that I leave the entire URL the same. If I go to / resources / new and click submit in the form that says
After creating, you usually redirect to something or visualize a new action in the create call to save information about the current object (for example, errors) that would be lost during the redirection. You currently remain in the create action (without rendering / redirecting another action), so the rails expect the create.html.erb
template.
Example:
def create @resource = Resource.new(params[:resource]) if @resource.save
Keep in mind that .new creates a new object, but it is not stored in the database unless you call, for example, .save.
These are just my opinions and experiences on this subject, so if someone more experienced thinks that something is wrong, I am glad to read the comment and update my answer.