Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jeditable and rails 3

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?

like image 347
Fabien Avatar asked Nov 05 '22 10:11

Fabien


1 Answers

Is overview an attribute of project? Then it should be

@project.overview = params[:value]
like image 149
kschaper Avatar answered Nov 11 '22 03:11

kschaper