0

This code snippet is extracted from a controller route. The intent is to render the partial after the form has being saved.

post :create, :provides => :js do
  @note = Note.new(params[:note])
  if @note.save
    "$('form').after('<p>#{ partial("notes/elikem") }</p>')"
    # Not sure why the partial above does not load
  else
    "alert('Note was not created');"
  end
end

This is the exact code we are concerned with... the partial renders when called from a view.

"$('form').after('<p>#{ partial("notes/elikem") }</p>')"

Useful reference: http://padrinorb.com/guides/application-helpers/ujs-helpers/

Eli
  • 85
  • 1
  • 8

1 Answers1

0

The problem was that a newline character was being added at the end of the string. This stopped javascript from being because it could not interpret it.

The solution was to use chomp which removes newlines at the end of a string. "$('form').after('<p>#{ partial("notes/elikem").chomp }</p>')"

Eli
  • 85
  • 1
  • 8