Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Rails Controller Action Method Requires Parameter

It's a brand new project. Here's the exact commands I've run:

  1. rails new MyProject
  2. bundle install
  3. rails generate controller Image

I've added this one route:

  1. root :to => "image#process"

I've added this function to the ImageController (image_controller.rb)

def process
  render :nothing => true
end

And finally I've removed the default index.html. When I run the project, it has an error saying process expects 0 parameters, not 1. So I modify the method to tell me what parameter is trying to be sent to process.

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

The string "process" is printed to the screen. I've done several Rails projects before and never encountered this. Did I miss a step somewhere? Is this something new in Rails 3.0.10? Or maybe caused by Ruby 1.9.2? I think I usually use 1.8.7.

like image 860
Spidy Avatar asked Jun 13 '12 19:06

Spidy


2 Answers

You can not name an action as process, this is an internal method for rails controllers, name it something else.

There's a bunch of other names you can't use for controller actions like render, params, request. Unfortunately there isn't a list of these things.

like image 136
Maurício Linhares Avatar answered Nov 15 '22 09:11

Maurício Linhares


For future reference, in case you aren't using it, you can view all internal methods and classes here: ruby doc with nav on top right

Helps me when picking names.

like image 38
craigmartin Avatar answered Nov 15 '22 10:11

craigmartin