Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Rails para Iniciantes - Aula 40

Ruby on Rails para Iniciantes - Aula 40

Criando pesquisas com o Ransack (Básico) 40

Jackson Pires

May 19, 2015
Tweet

More Decks by Jackson Pires

Other Decks in Programming

Transcript

  1. Ruby on Rails Index Customer Products Usuários Autenticados (normal_user, admin)

    Addresses ControlUsers Usuários Autenticados (admin)
  2. Ruby on Rails Na View <%= search_form_for @q do |f|

    %> <%= f.label :description_cont %> <%= f.search_field :description_cont %> <%= f.submit %> <% end %>
  3. Ruby on Rails Adicionando mais opções de pesquisa na view

    <%= f.label :quantity_lteq %> <%= f.search_field :quantity_lteq %>
  4. Ruby on Rails Pesquisas não restritivas AND => OR def

    index @q = Product.ransack(params[:q].try(:merge, m: 'or')) @products = @q.result end
  5. Ruby on Rails Automatizando o E/OU Na view <%= f.select

    :combinator, [[‘E’,’and’],[’OU’,’or’]], @q %> No controller @q = Product.ransack(params[:q].try(:merge, m: params[:combinator]))