Rails: Create a custom UI for a single specific object -
i've run problem i'm unsure how approach.
i have app sharing architectural photos. users have_many
photos, , users can create collections have_many
photos.
now have 1 customer big name in industry work me create totally customized collection different , feel "regular" collections, same functionality underneath. i'd accommodate request, have no idea how it.
given have functioning collection
model , collectionscontroller
, plus views, i'd re-use of possible. so, instance, custom collection needs override user facing :show view, not admin :edit view.
how approach this?
i'm trying understand efficient, dry method creating custom ui single record in database. i'd appreciative of suggestions, including links articles / books etc, haven't been able find in area.
i allow creation of liquid view templates associated user and/or collection (if want both - per-user templates per-collection variations - use polymorphic association) , of course fall default view (also built liquid consistency , reference) cases no custom template found.
edit add suggested details:
any custom templates should stored in database (i add test/preview function user entering custom template has chance verify template before publishing it):
# table name custom_templates # id :integer # templatable_type :string # templatable_id :integer # contents :text class customtemplate < activerecord::base belongs_to :templatable, :polymorphic => true end class user has_one :custom_template, :as => :templatable end class collection has_one :custom_template, :as => :templatable end
in controller action, custom template:
custom_template = @collection.custom_template custom_template ||= @user.custom_template @custom_template = liquid::template.parse(custom_template.contents) if custom_template
in view, either render custom template or default template partial:
<% if @custom_template -%> <%= @custom_template.render(_hash_of_objects_to_pass_to_liquid_template_) %> <% else -%> <%= render :partial => 'default' %> <% end -%>
Comments
Post a Comment