I'm trying to refactor some legacy code at the moment. It currently goes something like this:
Controller
def create
# do stuff
respond_to do |format|
format.html { do stuff }
format.js { render partial: 'stage_two', locals: { some instance variables } }
end
end
Then in the views/controller_name/_stage_two.js.erb there is:
$('.some_element').children().fadeOut( function() {
$('.some_element').children().remove();
$('.some_element').html("<%=j render partial: 'form', locals: { stuff } %>");
$('.some_element .stage_two').fadeIn();
});
So basically the controller action is essentially rendering javascript. And that particular javascript is just removing an element from the page, changing the contents, then fading it back in. Is there a better way to do this? I know typically javascript lies in the app/assets/javascripts.