# Object Task at episode 74 of railscasts

**URL:** <https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774>\
**Category:** Rails\
**Created:** [June 18, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774 "2008-06-18T13:07:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/1 "2008-06-18T13:07:15Z")

</div>

Hi.

In the episode 74 [http://railscasts.com/episodes/74](http://railscasts.com/episodes/74), Ryan has a model  
“project” that can have many “tasks”, and he uses link\_to\_function to  
dynamically add a field in the form for a new Task.

In order to do that he created a helper called add\_task\_link. The code  
of  
the method is:

# projects\_helper.rb

def add\_task\_link(name)  
link\_to\_function name do |page|  
page.insert\_html :bottom, :tasks, :partial =\> ‘task’, :object =\>  
Task.new

end  
end

The problem i have here is that i can’t figure out where does this Task  
object,  
which he instantiate with Task.new in the line i highlighted, come from.

Thanks,

–  
Guerra

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/2 "2008-06-18T14:10:07Z")

</div>

Task is a model that he have created before

2008/6/18, Israel G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/3 "2008-06-18T14:18:44Z")

</div>

Hi Oscar,

thanks for answering.

I understand that. I’m reproducing something very similar to what ryan  
does  
at the cast and i also have the corresponding model. In my app it’s  
called  
Client\_phones.

When i call Client\_phone.new in the same place ryan does, i get an error  
that says that client\_phones should have a method Client\_phone.

What would be that method? What am i missing here?

My Client\_phones model has only a belongs\_to client up to now.

Thanks,

On Wed, Jun 18, 2008 at 9:09 AM, Oscar Del B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > In order to do that he created a helper called add\_task\_link. The code of
> 
> >

–  
Guerra

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/4 "2008-06-18T14:30:19Z")

</div>

I can’t get in my mind the complete code, I can only suggest to copy  
(and  
understand) Ryan’s code, and then replace his models with yours

2008/6/18, Israel G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/5 "2008-06-18T14:33:58Z")

</div>

On 18 Jun 2008, at 13:17, Israel G. wrote:

> Hi Oscar,
> 
> thanks for answering.
> 
> I understand that. I’m reproducing something very similar to what  
> ryan does at the cast and i also have the corresponding model. In my  
> app it’s called Client\_phones.

That’s pretty much guarenteed to cause trouble. classes should be  
camelcased & singlular ie your class should be ClientPhone and be in  
client\_phone.rb

Fred

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/6 "2008-06-18T16:49:32Z")

</div>

Hi Fred.

The name of my model is Client\_phone and the name of the class in it is  
“ClientPhone”.

I think its correct, since it was generated automatically.

My code is exactly like Ryan’s, but for my models.

I wrote every code as he shows in the episode 73 and 74. He never shows  
the  
code for The Task model, that would be my Client\_phone.

The call for Task.new i have doubts about, would return, in my opinion,  
an  
object representing what is the Task model, but i don’t know if i should  
implement the function in the model or not. And if i should, i don’t  
have  
any clues of what code would go in there.

I’m at work now, later i can post my files here.

Thanks for helping.

On Wed, Jun 18, 2008 at 9:33 AM, Frederick C. \<  
removed\_email\_address@domain.invalid\> wrote:

> > app it’s called Client\_phones.  
> > What would be that method? What am i missing here?  
> > Hi.  
> > link\_to\_function name do |page|  
> > Task object,
> 
> >

–  
Guerra

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 18, 2008, 9:44pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/7 "2008-06-18T21:44:28Z")

</div>

Someone who watched the cast, maybe can tell me what they think there is  
in  
the Task model that allows him to call the new procedure the way he  
does.

Thanks.

On Wed, Jun 18, 2008 at 11:48 AM, Israel G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> code for The Task model, that would be my Client\_phone.
> 
> > > thanks for answering.
> > 
> > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> > > code of the method is:  
> > > end
> > > 
> > > –  
> > > Guerra
> > > 
> > > >
> > 
> > > >
> 
> –  
> Guerra

–  
Guerra

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 19, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/object-task-at-episode-74-of-railscasts/140774/8 "2008-06-19T21:42:00Z")

</div>

Probably I don’t understand, but .new() is a standard ruby method that’s  
available on every class. It’s how you create an instance of the class.  
So this is valid ruby:

class MyClass  
end

x = MyClass.new

So… you don’t need to have anything in your class definition to be  
able to call .new() on it.

* * *

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Israel G.  
Sent: Wednesday, June 18, 2008 12:44 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] Re: Object Task at episode 74 of railscasts

Someone who watched the cast, maybe can tell me what they think there is  
in the Task model that allows him to call the new procedure the way he  
does.

Thanks.

On Wed, Jun 18, 2008 at 11:48 AM, Israel G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi Fred.

The name of my model is Client\_phone and the name of the class  
in it is “ClientPhone”.

I think its correct, since it was generated automatically.

My code is exactly like Ryan’s, but for my models.

I wrote every code as he shows in the episode 73 and 74. He  
never shows the code for The Task model, that would be my Client\_phone.

The call for Task.new i have doubts about, would return, in my  
opinion, an object representing what is the Task model, but i don’t know  
if i should implement the function in the model or not. And if i should,  
i don’t have any clues of what code would go in there.

I’m at work now, later i can post my files here.

Thanks for helping.

On Wed, Jun 18, 2008 at 9:33 AM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

```
On 18 Jun 2008, at 13:17, Israel G. wrote:

> Hi Oscar,
>
> thanks for answering.
>
> I understand that. I'm reproducing something very

```

similar to what  
\> ryan does at the cast and i also have the  
corresponding model. In my  
\> app it’s called Client\_phones.  
\>

```
That's pretty much guarenteed to cause trouble. classes

```

should be  
camelcased & singlular ie your class should be  
ClientPhone and be in  
client\_phone.rb

```
Fred

> When i call Client_phone.new in the same place ryan

```

does, i get an  
\> error that says that client\_phones should have a  
method Client\_phone.  
\>  
\> What would be that method? What am i missing here?  
\>  
\> My Client\_phones model has only a belongs\_to client up  
to now.  
\>  
\> Thanks,  
\>  
\> On Wed, Jun 18, 2008 at 9:09 AM, Oscar Del B.  
\> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
\> Task is a model that he have created before  
\>  
\> 2008/6/18, Israel G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
\> Hi.  
\>  
\> In the episode 74, Ryan has a model “project” that can  
have many  
\> “tasks”, and he uses link\_to\_function to dynamically  
add a field in  
\> the form for a new Task.  
\>  
\> In order to do that he created a helper called  
add\_task\_link. The  
\> code of the method is:  
\>  
\> # projects\_helper.rb  
\> def add\_task\_link(name)  
\> link\_to\_function name do |page|  
\> page.insert\_html :bottom, :tasks, :partial =\>  
‘task’, :object =\>  
\> Task.new  
\>  
\>  
\>  
\>  
\> end  
\> end  
\>  
\> The problem i have here is that i can’t figure out  
where does this  
\> Task object,  
\> which he instantiate with Task.new in the line i  
highlighted, come  
\> from.  
\>  
\>  
\>  
\>  
\>  
\> Thanks,  
\> –  
\> Guerra  
\>  
\>  
\>  
\>  
\>  
\>  
\>  
\> –  
\> Guerra  
\> \>

–  
Guerra

–  
Guerra
