Topic: in_place_editor_field

Hi,
Does anybody know how this is meant to work? I just can't for the life of me get it to do anything...
Thx
a

Re: in_place_editor_field

Sure, you can create an in place editor field on a model attribute like this:

<%= in_place_editor_field :some_model, :some_attribute %>

In that sense it behaves like text_field. Then in your controller you add this line (above the method definitions)

in_place_edit_for :some_model, :some_attribute

That's mostly all there is to it to get something simple set up. There's more details in the Rails Recipe book if you have it.

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

Hi Ryan,
Thanks for that - I havn't got the Recipe book but I'll get it as it looks pretty useful.

I tried what you said but didn't have much joy. This is what I tried:

in_place_edit_for :task_list, :title

in my controller file and I added
<%= in_place_editor_field :TaskList, :title %>

and that in one of my view files yet I got the error:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

Have I done something stupid? It wouldn't surprise me.

Thanks again

Re: in_place_editor_field

In the code you have there, you have ":task_list" in your controller and ":TaskList" in your view.. they need to be the same

Re: in_place_editor_field

Yeh, sorry - they were both TaskList when I tried it. They should be called the name of the class right? Rails finds the file based on that doesn't it?

Re: in_place_editor_field

Yeah, they should be called the name of the model, but lowercase with underscores - not capital. Does it work when both are task_list?

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

Didn't work either either task_list or TaskList sad

Re: in_place_editor_field

Are you getting any errors or anything? Is the server even receiving a request upon clicking edit?

Make sure you have JavaScript libraries loaded:

<%= javascript_include_tag :defaults %>

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

JS libraries are loaded as I'm using script.aculo.us effects. Nothing happens - when I put the code in - it triggers the error above on the tag in the view file.

Re: in_place_editor_field

Is the @task_list instance variable set in the view where you call in_place_editor_field?

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

def index
    @task_list = TaskList.find(:all, :order => "title")
end

Thats what I have at the moment.

Last edited by shadow (2006-09-03 17:09:51)

Re: in_place_editor_field

I'm not sure, but it might be because you're instance variable relates to all of the rows in the db, not an individual row, so ActiveRecord does not know which to update...

try this:

<% for task in @task_list %>
<%= in_place_editor_field :task, :title %>
<% end %>

Re: in_place_editor_field

That brought back the same error - the nil one above sad

Re: in_place_editor_field

@task_list should relate to one instance of TaskList, not all of them. Try:

def index
  @task_list = TaskList.find(:first) # or params[:id] here to fetch a specific one
end

<%= in_place_editor_field :task_list, :title %>

Last edited by ryanb (2006-09-03 17:45:24)

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

Thanks Ryan - brilliant smile

Unfortunatly I use @task_list in a render paritial collection to show a list of task lists. As I've got a list whats would be the best way to create a @instance for each item for use with the editor?

Currently, each list is in a seperate view (so I have tasklist.field etc... for each list) in a loop (through render :partial :collection)

Re: in_place_editor_field

In your task list partial you can set the task list instance variable there. Like this:

<% @task_list = tasklist %>
<%= in_place_editor_field :task_list, :title %>

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

Thanks Ryan - that works. Although now whenever I try to submit a change I get a JS alert saying that no action exists - as if there wasn't an entry in the controller. I have:

in_place_edit_for :TaskList, :title

.

Re: in_place_editor_field

That should be:

[codel=ruby]
in_place_editor :task_list, :title
[/code]

You pretty much never use capital letters in symbols.

Railscasts - Free Ruby on Rails Screencasts

Re: in_place_editor_field

OK - thanks Ryan - worked wonderfully.

Is there any documentation for this function? Just wondering if its possible to change things like the highlight to and from colours?

Thanks again.

Re: in_place_editor_field

There's some documentation on the Scriptaculous site, but that's for the JavaScript side. Most of the parameters can be specified in the Rails helper method, but it may take a little bit of guess work.

Last edited by ryanb (2006-09-04 11:32:11)

Railscasts - Free Ruby on Rails Screencasts