yappbox / render_anywhere

Render Rails templates to a string from any class.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rendering a partial

PragTob opened this issue · comments

Hi there,

thanks for your work!

I'd like it to be possible to render a partial easily through just render my_object - which then calls to_partial_path sets the right locals and renders it.

When I try it, I get an error because it tries to name space it as render_anywhere which of course does not work, e.g.:

ActionView::MissingTemplate: Missing partial render_anywhere/cover_pages/_cover_page with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder]}. Searched in:

Maybe it's already possible and I'm just missing something.

Thank you!
Tobi

I was able to get partials working using something like:
render :partial => "#{role}/user/user_links"
but when I try to set a local variable:

    render :partial => "#{role}/user/user_links",
               :locals => { :user => user }

I get a

ActionView::Template::Error:
       wrong number of arguments (0 for 1..2)

I think I fixed it in the meantime by defining my own controller in my own namespace... I'm off the project now though :)

I'm having a similar issue on Rails 4.

Partials referenced from the template are being resolved to render_anywhere/rendering/_{#template_name}.erb. Is there any way to resolve them to the same directory as the template doing the rendering?

I had the same issue, mainly concerning polymorphic records rendering. Solved it like this:
render partial: "#{polymorphicable.class.table_name.to_s}/#{polymorphicable.class.to_s.underscore}}", locals: {polymorphicable.class.to_s.underscore.to_sym => polymorphicable}
It's not as clean as before, but works for me. It would be great if we don't have to do this in the future though.