Why does the Rails controller action method require a parameter

This is a completely new project. Here are the exact commands that I executed:

  • rails new MyProject
  • bundle install
  • rails generate controller Image

I added this route:

  • root :to => "image#process"

I added this function to ImageController ( image_controller.rb )

 def process render :nothing => true end 

And finally, I removed the default index.html . When I run the project, it has an error stating that the process expects 0 parameters, not 1. Therefore, I change the method to tell me which parameter the process is trying to send.

 def process(arg) p arg render :nothing => true end 

The line "process" is printed on the screen. I have done several Rails projects before and have never come across this. Did I miss something? Is this something new in Rails 3.0.10? Or can it be caused by Ruby 1.9.2? I usually use 1.8.7.

+6
source share
2 answers

You cannot name an action as a process , it is an internal method for rails controllers, call it something else.

There are many other names that you cannot use for controller actions, such as render, params, request. Unfortunately, a list of these things is missing.

+11
source

In the future, if you do not use it, you can view all internal methods and classes here: ruby doc with navigation in the upper right corner

Helps me in choosing names.

+1
source

Source: https://habr.com/ru/post/918016/


All Articles