Where is the definition of render method?

Hi all,

I am a begginer on Ruby on Rails, and have only a month experience about
ruby itself.
Before doing this, I have worked for some works using C/C++ and PHP for
several years.

I’ve been learning with a few books since last thursday and had a
question
about render method.
I made a Rails application named ‘hello’ with command execution ‘rails
generate controller hello’.
Then found the file, which was generated as ‘hello_controller.rb’. It
was
like this:

class HelloController < ApplicationController
end

The book I’ve been using suggests adding a method, for example:

class HelloController < ApplicationController
def index
render :text => ‘hello world’
end
end

I know this code works, but I couldn’t find the definition of render
method
in the API document
at http://api.rubyonrails.org, probably because I was(am) new to these
document.

But I wanted to know what the render method can do,
so I tried to make some codes to find the definition as bellow, and saw
the
result.

– hello_controller.rb –
class HelloController < ApplicationController

def index
@controller_name = self.class.to_s
included_modules = self.class.included_modules

@ancestors = self.class.ancestors
ancestor_classes = @ancestors - included_modules

@ancestor_classes =
  ancestor_classes.map{|ac|
    [ac, [eval("#{ac}.class.public_instance_methods"),
          eval("#{ac}.class.protected_instance_methods"),
          eval("#{ac}.class.private_instance_methods")]]
  }

 @included_modules =
  included_modules.map{|im|
    [im, [eval("#{im}.class.public_instance_methods"),
          eval("#{im}.class.protected_instance_methods"),
          eval("#{im}.class.private_instance_methods")]]
  }
  @included_modules.delete_if{|e| e[1][0] == nil}

end
end

– index.html.erb –

<%[email protected]_name -%>class list

    <% @ancestor_classes.each do |ac| %>
  • <%= ac[0] %>

    public methods
      <% ac[1][0].each do |method| %>
    • <%= method %>
    • <% end %>
    protected methods
      <% ac[1][1].each do |method| %>
    • <%= method %>
    • <% end %>
    private methods
      <% ac[1][2].each do |method| %>
    • <%= method %>
    • <% end %>
  • <% end %>

<%[email protected]_name -%>included modules

    <% @included_modules.each do |im| %>
  • <%= im[0] %>

    public methods
      <% im[1][0].each do |method| %>
    • <%= method %>
    • <% end %>
    protected methods
      <% im[1][1].each do |method| %>
    • <%= method %>
    • <% end %>
    private methods
      <% im[1][2].each do |method| %>
    • <%= method %>
    • <% end %>
  • <% end %>

But this didn’ work. Even a definition named ‘render’ wasn’t found.
Is the above code wrong? of course that is possible, I think.
Or, simply I should look up any other good API document site,
which is easier to use for begginers like me??

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs