Object Task at episode 74 of railscasts

Hi.

In the episode 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

Task is a model that he have created before

2008/6/18, Israel G. [email protected]:

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. [email protected]
wrote:

In order to do that he created a helper called add_task_link. The code of


Guerra

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. [email protected]:

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

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. <
[email protected]> 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

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.
[email protected]
wrote:

code for The Task model, that would be my Client_phone.

thanks for answering.

[email protected] wrote:
code of the method is:
end


Guerra


Guerra


Guerra

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: [email protected]
[mailto:[email protected]] On Behalf Of Israel G.
Sent: Wednesday, June 18, 2008 12:44 PM
To: [email protected]
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.
[email protected] 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.
[email protected] 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.
> [email protected] wrote:
> Task is a model that he have created before
>
> 2008/6/18, Israel G. [email protected]:
> 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