2

My problem is this, I'm implementing as homework a sort of web site like stackoverflow of questions and answers and what I want to do is to make an ajax request when a user fills a form to create answer inside the view 'show' of a current question to update this view without having to load again the entire view.
I already know how to make ajax request works when the action and the view belong to the same controller, but in this case the answer is going to be save in a different scaffold, so I don't know how to chain the results of calling the action in the Answers controller to the action that show the view in the Questions controller, neither what .js.erb should I create:
for the action 'show' in Questions controller, or
for the action 'create' in Answers controller

Thanks in advance for any help.

1 Answer 1

0

As your save answer goes to create action of answer controller then you should have a create.js.erb with sort of the following code:

answers/create.js.erb

$('#answers').append('<%= escape_javascript("#{render :partial => 'answers/details', :locals => {answer: @answer}}".html_safe)%>');

provided that you have answers/_detail.html.erb partial to render answer detail.

1
  • Didn't work to me. I edited the question because I think I wasn't clear enough. But what you post me is the situation I already know how to handle. Jun 16, 2013 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.