1

I have a link_to_remote to render the edit action of an object. But all it does is update the Dom Element with this response

try { } catch (e) { alert('RJS error:\n\n' + e.toString()); alert(''); throw e }

My link looks like this:

= link_to_remote t("txt.edit"), :update => dom_id(comment), :url => edit_comment_path(comment.id)

My edit action in the comment controller:

  # GET /comments/1/edit
  def edit
    @comment = Comment.find(params[:id])
    respond_to do |format|
      format.html
      format.js { render :action => "edit" }
    end
  end

The request seems to be ok, according to the log:

Processing CommentsController#edit (for 127.0.0.1 at 2009-04-08 18:55:36) [GET]
  Session ID: 1d4b9b3d3319d5cd556d00d2e053b651
  Parameters: {"authenticity_token"=>"5d70f9e5beded361ee7e87ee591512411e8f3eec", "id"=>"18"}
  User Columns (2.0ms)   SHOW FIELDS FROM `users`
  User Load (0.5ms)   SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
  Account Columns (1.6ms)   SHOW FIELDS FROM `accounts`
  Account Load (0.2ms)   SELECT * FROM `accounts` WHERE (`accounts`.`subdomain` = 'xxx') LIMIT 1
  Comment Columns (1.7ms)   SHOW FIELDS FROM `comments`
  Comment Load (0.6ms)   SELECT * FROM `comments` WHERE (`comments`.`id` = 18) 
Rendering comments/edit
Completed in 30818ms (View: 2, DB: 7) | 200 OK [http://xx.xxx.rails/comments/18/edit?authenticity_token=5d70f9e5beded361ee7e87ee591512411e8f3eec]

What am I doing wrong? Thanks for the help!

UPDATE: It works by the way with a RJS template - that's how I solved it now. But I still prefer a solution where a view is rendered. Otherwise I have to create a partial just for this purpose (I cannot render Views with rjs page updates - at least I don't know how).

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160

6 Answers6

1
:script => true

Add this to the link_to_remote call and it should make rails evaluate any scripts returned, rather than outputting them plain-text.

Owain Hunt
  • 4,619
  • 2
  • 20
  • 10
1

Or do not catch "respond_to" at all since in both cases You are doing the same! Just comment out:

respond_to do |format|
  format.html
  format.js { render :action => "edit" }
end
aivarsak
  • 279
  • 1
  • 6
0

When you are responding to a js request, render :action => "edit" will try to render edit.rjs, a rjs 'template', not edit.haml, an html template.

mckeed
  • 9,719
  • 2
  • 37
  • 41
0

Remove the :update option from your RJS tag. I had one in there and when I was trying to insert_html it was displaying the JS returned from the method and not executing it on the DOM. So it was displaying => try {...}

I took the :update attribute out of my link_to_remote statement in my view, used a render: update do |page| page.insert_html(...) end block and it executed the JS returned instead of displaying it.

Hope that helps.

0

The one thing you neglected to mention is what the template is... I'm guessing that's the problem. If it's ERB try something like:

format.js { render :action => "edit.html.erb" }

AdminMyServer
  • 916
  • 8
  • 10
0

It looks like you may have forgotten to include a reference to the Javascript libraries in your views, and the view is rendering the literal JavaScript instead of interpreting it.

<%= javascript_include_tag :defaults %>
yalestar
  • 9,334
  • 6
  • 39
  • 52