Object Task at episode 74 of railscasts

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,

Task is a model that he have created before

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,

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

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.

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.

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.