Je réécris la méthode de rendu du contrôleur, cependant, je souhaite utiliser l'ancienne méthode dans la méthode render_to_string. Ce sont mes codes actuels:Chaîne de méthode Alias dans ruby s'appelant
def render_with_xhr(options = {}, extra_options = {}, xhr_check = true, &block)
if xhr_check && request.xhr?
template = render_to_string(options)
render_without_xhr(:update) {|page| page.replace_html("#popup .dialog", template)}
else
render_without_xhr(options, extra_options, &block)
end
end
alias_method_chain :render, :xhr
Ce qui se passe est que, depuis render_to_string fait usage de rendre (sans doute), je finis dans une boucle infinie. Comment puis-je faire revenir à l'ancienne méthode juste pour cette ligne ma nouvelle méthode de rendu?
J'ai modifié les codes de la réponse acceptée, le code final est ci-dessous:
def render_to_string(options = {}, &block)
render(options, {}, false, &block)
ensure
response.content_type = nil
erase_render_results
reset_variables_added_to_assigns
end
def render_with_xhr(options = nil, extra_options = {}, xhr_check = true, &block)
if xhr_check && request.xhr?
template = render_to_string(options)
render_without_xhr :update do |page|
page.replace_html("#popup .dialog", template)
end
else
render_without_xhr(options, extra_options, &block)
end
end
alias_method_chain :render, :xhr
Merci collègues redditor, je vais essayer et signaler =) – Jaryl