comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.73k stars 639 forks source link

Collection tag seems to be not working #224

Closed ticaje closed 12 years ago

ticaje commented 12 years ago

Hello, im trying to put into action the tag's functionallity Collection by doing exactly what wiki says, but it shows nothing. I have a collection of events that i would like to show in a template by putting this on an admin page layout: {{ cms:collection:events:events }}, where the ActiveRecord class is event(inside this class i defined the scope cms_collection) and i have a partial called events where i put the cycle in order to show the events one by one. I guess this is the way the wiki explains this feature. Please if im missing something i would appreciate any help. Thanks a lot.

GBH commented 12 years ago

Collection is a really awkward tag to use. It's strange that nothing crashes if you got it wrong. It really just constructs a partial. See this for details: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/tags/collection.rb

But from what I can see in your case it should look something like this: {{cms:collection:event:events}}

event translates to Event.all and events is partial events

ticaje commented 12 years ago

That's exactly what im doing and nothing happens, im stuck on this issue, please if this could sound familiar to somebody...

ticaje commented 12 years ago

Hi Oleg, i was wondering if the problem could be by the fact that my model is proper of my own application and is some kind of outsider for CMS. Jus wandering, what do you think about it, cause there is nothing more that could suggest me anything else. Thank you for your time.

On 09/24/2012 05:23 PM, Oleg wrote:

Collection is a really awkward tag to use. It's strange that nothing crashes if you got it wrong. It really just constructs a partial. See this for details: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/tags/collection.rb

But from what I can see in your case it should look something like this: |{{cms:collection:event:events}}|

|event| translates to |Event.all| and |events| is partial |events|

— Reply to this email directly or view it on GitHub https://github.com/comfy/comfortable-mexican-sofa/issues/224#issuecomment-8822572.

Héctor Barrientos, Ingeniero Informático.

GBH commented 12 years ago

You really need to debug it somehow. You can go directly into cms code and start raising stuff. It's pretty suspect that nothing shows up. Invalid collection tag should technically blow up as it will construct an invalid partial call.

Try posting more information about how it's all structured. As far as I know it really should work, and I can't guess without knowing more about what's going on in your app.

ticaje commented 12 years ago

Oleg, thank you one more time for your time and dedication, in few details i expose you how did i put all things together in order to integrate CMS with my application:

Thank a lot

anthonylebrun commented 12 years ago

I'm having the same issue as @ticaje and pretty much followed the steps he lists above.

def render
    if self.content.present?
        ps = collection_params.collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
        ps = ps.present?? ", #{ps}" : ''
        "<%= render :partial => '#{collection_partial}', :locals => {:model => '#{collection_class}', :identifier => '#{content}'#{ps}} %>"
    else
        ''
    end
end

In my case, debugging shows that the else clause is always being executed, which would explain why render is not blowing up. @GBH I'm a little confused by what self.content represents in the context of a cms:collection, could you give us a simple and complete use case for the collection tag?

GBH commented 12 years ago

Maybe there's a confusion about what this tag does. This is what it allows you to do:

So self.content bit is the id of the item you've selected. If nothing was selected, nothing will be rendered. Tests show implementation: https://github.com/comfy/comfortable-mexican-sofa/blob/master/test/unit/tags/collection_test.rb

anthonylebrun commented 12 years ago

@GBH Oh ok, there was indeed confusion about it's purpose (I now have it working the way you meant it). What I was intending to do was the equivalent of rails render :partial with the :collection => @items option. Would the solution here be to use an erb/haml layout for every page that I intend to do this on instead of trying to use CMS?

GBH commented 12 years ago

Yes. You probably want just to render a partial. So define a {{cms:partial}} tag on the layout. Or have it inside your erb/haml layout.

barnett commented 10 years ago

@GBH Is it possible to do collection with a non AR class? I load a constant from a yml file and call it via MapChoices['county']. How would I use a collection tag on such an array?