Is it possible to use redis with Padrino same as postgresql or mysql generators.
Asked
Active
Viewed 544 times
1 Answers
1
Take a look at Ohm
. It's an ORM supported by Padrino that is similar to Active Model but uses Redis as it's datastore.
You might want to build Padrino from master or wait for 0.11.2 if you are looking to use 'Padrino Admin' with Ohm.
padrino g project my_app --orm ohm
cd my_app
bundle
padrino g model Post title:string body:text
padrino g admin
padrino g admin_page post
padrino rake db:seed
padrino start
EDIT: Here is one way of adding a collection to Padrino admin page with Ohm as the ORM.
Open your generated admin/views/presentations/index.erb
and display your collection in the table.
<td class=list-column>
<% presentation.slides.each do |slide| %>
<div><%= slide.name %></div>
<% end %>
</td>
Open admin/views/presentations/_form.erb
and add a check_box_group
for your collection.
<fieldset class='control-group <%= error ? 'has-error' : ''%>'>
<%= f.label :slides, :class => 'control-label' %>
<div class='controls'>
<%= f.check_box_group(:slide_ids, collection: @slides, selected: @presentation.slides, fields: [:name, :id]) %>
</div>
</fieldset>
From there you can update your Presentations controller to handle params[:presentation][:slide_ids]
or you add the following method to your Presentation model.
def slide_ids=(ids)
if valid? && save
slides.key.del if slides.key.exists?
slides.key.sadd(ids)
end
end
Which will replace the current set of slides with the new set.

lastcanal
- 2,145
- 14
- 17
-
will datamapper provide support for redis better than Ohm? I can't figure out a way to make one-to-many or many-to-many relationships and have it applied in the admin views? any clues how to do that? – zotherstupidguy Apr 17 '13 at 17:08
-
1Currently `Ohm::Model.attributes` only returns attributes and not associations. [Here is how the Padrino Admin Generator handles columns for both Ohm and DataMapper](https://github.com/padrino/padrino-framework/blob/master/padrino-admin/lib/padrino-admin/generators/orm.rb#L58). It would be possible to inject `Ohm::Model.collections` into `Ohm::Model.attributes` and handle the special cases in the [admin page templates](https://github.com/padrino/padrino-framework/blob/master/padrino-admin/lib/padrino-admin/generators/templates/haml/page/index.haml.tt#L44). – lastcanal Apr 17 '13 at 17:29
-
I don't actually think DM applies associations to admin views. Take a look at this [un-merged pull request](https://github.com/devrandom/padrino-framework/commit/78478d9a373eb16c08373158af22ab80387fe496) from a couple years ago. – lastcanal Apr 17 '13 at 17:38
-
i thought something basic like this should be easy in padrino as i read that this is pretty basic to django!! I have a presentation model and slides model, i just want to be able to add more than one slide to a presentation model from the padrino admin, is this easy? can it be generated by a padrino command? any samples for this? ohm/redis? – zotherstupidguy Apr 18 '13 at 04:17
-
Padrino supports a number of ORM's and they each do this differently. It would be great if it was supported automatically though! I've updated my answer with some info on how to get started with associations in Padrino Admin. Hope it helps! – lastcanal Apr 18 '13 at 14:38