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 --
<h1><%=@controller_name -%>class list</h1>
<ul>
<% @ancestor_classes.each do |ac| %>
<li>
<h2><%= ac[0] %></h2>
<dl>
<dt>public methods</dt>
<dd>
<ul>
<% ac[1][0].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
<dt>protected methods</dt>
<dd>
<ul>
<% ac[1][1].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
<dt>private methods</dt>
<dd>
<ul>
<% ac[1][2].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
</dl>
</li>
<% end %>
</ul>
<h1><%=@controller_name -%>included modules </h1>
<ul>
<% @included_modules.each do |im| %>
<li>
<h2><%= im[0] %></h2>
<dl>
<dt>public methods</dt>
<dd>
<ul>
<% im[1][0].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
<dt>protected methods</dt>
<dd>
<ul>
<% im[1][1].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
<dt>private methods</dt>
<dd>
<ul>
<% im[1][2].each do |method| %>
<li><%= method %></li>
<% end %>
</ul>
</dd>
</dl>
</li>
<% end %>
</ul>


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??

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/K2PImv1pcYQJ.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 15, '12 at 7:19p
activeOct 15, '12 at 7:19p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Somohan: 1 post

People

Translate

site design / logo © 2022 Grokbase