# View and Controllers association

**URL:** <https://www.ruby-forum.com/t/view-and-controllers-association/194905>\
**Category:** Rails\
**Created:** [September 13, 2010, 2:58pm UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905 "2010-09-13T14:58:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 13, 2010, 2:58pm UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/1 "2010-09-13T14:58:56Z")

</div>

in views file.

\<%= render ‘row’, :object =\> @row\_1 %\>

\_row\_html.erb

\<% row.each do |i| %\>  
\<%- if i.nil? -%\>  
\<%= render ‘users/signup’ %\>  
\<%- elsif i.respond\_to?(‘category\_id’) -%\>  
\<%# render partial\_for\_post(i.category\_id), :object =\> i %\>  
\<%= i.module %\>  
\<%- end -%\>  
\<% end %\>

if I write i.class it returns Post, so I thought module will be a  
method in post\_controller.rb. But it’s not, can any one tell me, what is  
it, and where can I get codes written for i.module.

Thanks

---

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 13, 2010, 3:03pm UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/2 "2010-09-13T15:03:07Z")

</div>

Am 13.09.2010 um 14:58 schrieb Awijeet Mr.:

> if I write i.class it returns Post, so I thought module will be a  
> method in post\_controller.rb. But it’s not

If i is of the type Post, i.module will call the method module from the  
Post object in app/models/post.rb, not from a PostsController object as  
you seem to think it will.

Felix

---

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 13, 2010, 4:11pm UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/3 "2010-09-13T16:11:37Z")

</div>

Post (singular with capital) is the model

---

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 14, 2010, 7:50am UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/4 "2010-09-14T07:50:37Z")

</div>

Felix SchÃ¤fer wrote:

> Am 13.09.2010 um 14:58 schrieb Awijeet Mr.:
> 
> > if I write i.class it returns Post, so I thought module will be a  
> > method in post\_controller.rb. But it’s not
> 
> If i is of the type Post, i.module will call the method module from the  
> Post object in app/models/post.rb, not from a PostsController object as  
> you seem to think it will.
> 
> Felix

I have checked the code in app/models/post.rb  
there are no module method, but at lot of space self.module function has  
been called, and a defined method is def set\_module

---

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 14, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/5 "2010-09-14T14:09:52Z")

</div>

Post. module is not the same as i.module, i is an instance of the Post  
class that means you can do  
Post.name == i.class.name and returns true.

acording to ruby docs this is what a module is

"A Module [http://ruby-doc.org/core/classes/Module.html](http://ruby-doc.org/core/classes/Module.html) is a collection  
of  
methods and constants  
[http://ruby-doc.org/core/classes/Module.html#M001656](http://ruby-doc.org/core/classes/Module.html#M001656).  
The methods in a module may be instance methods or module methods.  
Instance  
methods appear as methods in a class when the module is  
included[http://ruby-doc.org/core/classes/Module.html#M001660](http://ruby-doc.org/core/classes/Module.html#M001660),  
module methods do not. Conversely, module methods may be called without  
creating an encapsulating object, while instance methods may not. (See  
Module#module\_function[http://ruby-doc.org/core/classes/Module.html#M001642](http://ruby-doc.org/core/classes/Module.html#M001642))  
"

so what do you spect the module method to return from i.module?

---

<div class="post-metadata">

**Author:** ![awijeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/65b543/32.png) [@awijeet](https://www.ruby-forum.com/u/awijeet)\
**Post date:** [September 14, 2010, 7:52am UTC](https://www.ruby-forum.com/t/view-and-controllers-association/194905/6 "2010-09-14T07:52:34Z")

</div>

radhames brito wrote:

> Post (singular with capital) is the model

that’s true, but here instead of Post.module, i.module is called.  
and to know it’s class when i put i.class it said Post, and in  
app/models/post.rb

no module function is there… ☹
