ruby - Rails Render Action With Different Format -
say have application#search method respond ajax requests. inside of js view (app/views/application/search.js.erb) render html view:
$("#content").html( escape_javascript( render( :action => 'search', :format => 'html' ) ) ); $("#title").html( "title" );
i know move things partial , render in both html , js views, problem have many different actions need respond in way , i'd prefer not creating bunch of 1-line view files render partial.
is there way explicitly render action specific format , grab different parts of content_for well? above example, set #title html returned content_for :title or something.
i'm not sure outputting bunch of html js source great design, wasn't question -- , i've had similar things output html snippets rendered templates xml, consider more reasonable :).
anyhow, there several things in question.
it changes version version of rails, in rails 4.x, think should work, close, reason needs :formats
(plural) array. , there other unrelated things not right in example, need erb <%= tags, , putting javascript strings quote marks.
var str = "<%= escape_javascript( render( :partial => 'partial_name', :formats => ['html'] ) ) %>";
i think. haven't tried myself.
note that's still partial though. want render full (not partial) template inside template -- i'm pretty sure rails won't let that. it's been bit annoying me before too. in fact, render html partial ("something.html.erb") js partial, need use :formats => []
trick, or rails insist "hey, want find js partial name, we're in js mode man!".
but above should render _partial_name.html.erb js template. still not great design.
hope helps.
Comments
Post a Comment