views:

90

answers:

3

Hello ! I'm trying to use jeditable with my rails 3 apps. I would like to edit some fields inline. Actually it's working on my client side but the data isn't updated in my app.

Could you take a look? Thanks in advance!

my view:

<dt>Overview :</dt>
<dd class="edit_textfield" id="<%= @project.id %>" name="overview"><%= @project.overview %></dd>

my controller:

 def update
    project = Project.find(params[:id])
    overview = params[:value]
    project.save
    render :text => params[:value]
  end

my application.js:

$(".edit_textfield").each( function() {    
      $(this).editable('update', {
            type    :   'textarea',
            cancel  :   'Cancel',
            submit  :   'OK',
            indicator   :   'Saving...',
            tooltip :   'Click to edit...',
            rows        :       10,
            method      :       "put",
            submitdata  :   {id: $(this).attr('id'), name:$(this).attr('name') }
        });
});
A: 

I study rails not long, but I think the product need '@'.

Like this:

def update
  @project = Project.find(params[:id])
  overview = params[:value]
  @project.save
  render :text => params[:value]
end

Maybe...

Thanks rainisic, but it's still the same ;-)
Fabien
A: 

Is overview an attribute of project? Then it should be

@project.overview = params[:value]
kschaper
Thanks it works!!!! It was so basic... :oP
Fabien
A: 

Thanks to kschaper, it works.

But when I use jeditable for 2 fields in my page and that I edit them, only one is saved. Rails believe that the second value is 0

I think that the problem come from my controller :

  def update
    @project = Project.find(params[:id])
    @project.name = params[:name] 
    @project.overview = params[:overview]
    @project.save
    respond_to do |format|
      format.js  #{ render :text => params[:value] }

    end
  end

Do you have a clue?

Fabien
Maybe the update method is called everytime you enter something in a field. I would have a look at FireBugs console to check what is sent to the server. Or maybe both values have to be passed to the update method at once. Do you have any validations in your model which prevent the record from being saved?
kschaper