Hi,

I've got an ajax call who's response does some complicated things on
the view. I've already created this view in ruby on the server, so I'd
rather not rewrite the entire thing in javascript when the ajax call
returns.

It seems like it should be easy enough to resend the current view
(minus the layout) in response to the json call, but I'm having
trouble figuring out what should go in the controller.

In other words, here's the standard controller action:

# POST /my_controller
# POST /my_controller.json
def create
@my_controller = MyController.new(params[:my_controller])

respond_to do |format|
if @my_controller.save
format.html { redirect_to :back }
format.json { render json: @my_controller, status: :created,
location: @my_controller } # <--- here
else
format.html { redirect_to :back }
format.json { render json: @my_controller.errors, status:
:unprocessable_entity }
end
end
end

At the place I've marked "<--- here", I'd like to basically return
what would happen on "redirect :back" except I don't want the round
trip to the browser, nor the layout, and I'd like to return it as part
of the json object.

In other words, I'm looking for something like this:

format.json { render json: { html:
get_html(request.env['REQUEST_URI']) }, status: :created, location:
@my_controller } # <--- here

def get_html(uri)
# TODO: How do I render this and return it as a string?
# Obviously not the following, but that is the idea:
# html = render :template => uri, :layout => false
# return html
end

I hope my intent is clear...

Thanks!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 13, '12 at 1:39p
activeMar 13, '12 at 1:39p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Paul: 1 post

People

Translate

site design / logo © 2021 Grokbase