Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2012 04:14
Show Gist options
  • Select an option

  • Save anonymous/1686947 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1686947 to your computer and use it in GitHub Desktop.
def create
@device = Device.new(params[:device])
@device.user = current_user
# the respond to structure allows ajax to run
# but falls back to normal html form processing if
# javascript is disabled, I think
@save_status = false
@rendered_content = ""
if @device.save
@save_status = true
@rendered_content = render_to_string(:action => :show, :layout => false)
else
@rendered_content = render_to_string(:action => :new, :layout => false)
end
binding.pry
respond_to do |format|
format.html {
if @save_status
render 'show'
else
render 'new'
end
}
format.js # this will render the
end #respond_to
end #create
#create.js.erb
/* render the form response */
$('#content').html(Utility.htmlDecode("<%= escape_javascript(@rendered_content) %>"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment