5

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') }
        });
});

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?

casperOne
  • 73,706
  • 19
  • 184
  • 253
Fabien
  • 273
  • 5
  • 12

3 Answers3

2

Is overview an attribute of project? Then it should be

@project.overview = params[:value]
kschaper
  • 309
  • 1
  • 6
0

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...

rainisic
  • 65
  • 1
  • 7
0

FYI -- The ID attributes must start with a letter. What you have in your view won't pass validation. You'll need to prepend it with some text in your templates and then strip it out in your application.js before sending it along in the submit data.

IAmNaN
  • 10,305
  • 3
  • 53
  • 51