Search code examples
ruby-on-railsformslocaleditpartial

Passing local to partial rails


I dont know whats happenning. I just want to render an edit form via ajax, passing a local to a partial. my code is the following

Calling to edit action in my licencias_controller

<td><%= link_to '<i class="icon-pencil icon-black"></i>'.html_safe, edit_licencia_path(licencia), :remote => true %></td>

Here is my code in licencias_controller

      def edit
    @licencia = Licencia.find(params[:id])
    respond_to do |format|
      format.js {}
    end
  end

And here is my code in edit.js.erb

    $(document).ready(function(){

    $('#modContLicencia').replaceWith('<%= escape_javascript(render(:partial => 'edit', :locals => {:licencia => @licencia})) %>');
    $('#modLicencia').modal('show');
});

So what i want is to show @licencia data in a _edit partial. First time i click to see its rendered ok, but if i click another @licencia object in index, the partial render the same @licencia object.So @licencia object is not being updated when i click another time to edit it. What im doing wrong?


Solution

  • Your use of quotes are probably causing this problem for you. Your edit would be treated an a variable in the replaceWith line. You want to either escape the quotes wraping your edit partial using \' or use the following instead:

    $('#modContLicencia').replaceWith("<%= escape_javascript(render(:partial => 'edit', :locals => {:licencia => @licencia})) %>");