Вопрос

Is it possible to use redis with Padrino same as postgresql or mysql generators.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top