jquery - Specifying name of rails partial to render using a variable -
is possible in rails 3.0 render partial name of partial stored in variable?
i attempting similar to:
<%= escape_javascript(raw render :partial => @partial_name, :locals => { :value => @value} )%>
updated more details
in application have set of models using multi-table inheritance, example lets have base model 'cupcake' , variants such 'awesomecupcake' , 'alrightcupcake'.
each of these models have own custom partial displaying information , follow naming scheme: '_awesome_cupcake' , '_alright_cupcake'.
on page have links each type of cupcake in want controller accept parameter , dynamically derive partial render. following works wanted if (in new.js.erb file) replace '@partial_name' such 'awesome_cupcake'.
here little more information how components laid out:
application.js
$('#set_cupcake').click(function () { $.getscript('/cupcakes/new.js?cupcake_type=awesome'); });
cupcakes_controller.rb
def new cupcake_type = "#{params[:cupcake_type].capitalize}cupcake" if object.const_defined? cupcake_type @cupcake = cupcake_type.constantize.new @partial_name = "#{params[:cupcake_type]}_cupcake" end end
views/cupcakes/new.js.erb
$('#cupcakes') .append("<%= escape_javascript(raw render :partial => @partial_name, :locals => { :cupcake => @cupcake } ) %>")
of course. make sure @partial_variable string of name (such "header" , work fine.
Comments
Post a Comment