Sharing rails fragments between formats
Posted
by Julian
on Stack Overflow
See other posts from Stack Overflow
or by Julian
Published on 2010-05-29T22:04:44Z
Indexed on
2010/05/29
22:12 UTC
Read the original article
Hit count: 203
ruby-on-rails
|mobile-fu
Hi I'm toying with mobile_fu and want to share some fragments between the different views. E.g.
views/
item/
view.html.erb
view.mobile.rb
shared/
_common.erb
In both view.html.erb and view.mobile.erb I want to share the same fragment '_common.erb' without having to specify the format (should you ever have to specify the format inside a fragment? It doesn't seem like The Rails Way?). Let's say for arguments's sake it's because it's in a helper or whatever -- the point is that I need to share fragments in a 'well-defined and Railsy way' across formats.
Let's take this fairly innocuous snippet
<% render :fragment => 'shared/common' %>
I've tried 3 file name conventions:
- _common.html.erb only works for html
/item/view/xx
fails with 'shared/_common.erb not found'
) - however _common.erb fails for html and works for mobile (maybe mobile_fu is doing something wacky?) -- same error as for .html.erb version above
- _common.rhtml does work for both
I'm thinking that: that rhtml works for both is a legacy hack and I'm loathe to rename all the shared fragments .rhtml to get the behaviour I want.
Any feedback gratefully welcome! Including 'you fundamentally don't understand how Rails works please RTFM here: http://....'
:)
© Stack Overflow or respective owner