Comatose Drops - ActiveRecord Model

2 views
Skip to first unread message

bilson

unread,
Apr 28, 2009, 11:44:32 AM4/28/09
to Comatose Plugin
I must have missed it, but is there an example of a simple Comatose
drop involving an ActiveRecord model? In Rails, it's fairly easy to
setup Liquid in a model using...

liquid_methods :attribute1, :attribute2, etc.

In Comatose, I am not sure how to achieve the same. For example, I
have defined the following Comatose drop for the Person model...

Comatose.define_drop 'person' do
def all_people
Person.all
end
end

In the view I am hoping to achieve the following...

{% for p in person.all_people %}
<tr>
<td>{{ p.firstname}}</td>
<td>{{ p.lastname }}</td>
<td>{{ p.email }}</td>
</tr>
{% endfor %}

It doesn't surprise me that this doesn't work with just that, but I do
not know what to add to make it work in this manner. I have tried
adding the "liquid_methods" method to the ActiveRecord model, but that
did nothing.

I can get it to print out this information, but the method is poor...

Comatose.define_drop 'person' do
def all_people
Person.all.collect {|p| [p.firstname, p.lastname, p.email]}
end
end

{% for p in person.all_people %}
<tr>
{% for column in p %}
<td>{{ p.firstname}}</td>
{% endfor %}
</tr>
{% endfor %}

Is there a simple way to make this work? Thanks for your thoughts.

Best Regards,
David Baldwin

bilson

unread,
Apr 28, 2009, 1:11:14 PM4/28/09
to Comatose Plugin
Okay. Figured that out. Turns out it's quite easy...

Comatose.define_drop 'person' do
def all_people
Person.all.collect {|p| {"firstname" => p.firstname, "lastname" =>
p.lastname, "email" => p.email} }
end
end

Best Regards,
David Baldwin
Reply all
Reply to author
Forward
0 new messages