ransack

How to construct a clickable link with a scope using Ransack and Rails

☆樱花仙子☆ 提交于 2019-12-02 07:01:31
问题 I have the requirement to have some scopes as clickable links in my application. This will allow the user to change the data they are seeing as required. Using Ransack and it's ransackable_scopes functionality I am very close. I do need to retain any filtering Ransack has done when the user clicks the scope. I've got the scopes working but now I just need to construct the clickable link. Here's my model: class Product < ActiveRecord::Base scope :upward_trending, -> { where( "status > ?", 100)

How to construct a clickable link with a scope using Ransack and Rails

元气小坏坏 提交于 2019-12-02 04:23:26
I have the requirement to have some scopes as clickable links in my application. This will allow the user to change the data they are seeing as required. Using Ransack and it's ransackable_scopes functionality I am very close. I do need to retain any filtering Ransack has done when the user clicks the scope. I've got the scopes working but now I just need to construct the clickable link. Here's my model: class Product < ActiveRecord::Base scope :upward_trending, -> { where( "status > ?", 100).where(above_revenue_average: true).order('end_date DESC') } scope :downward_trending, -> { where(

Rails filter with button or link_to using Ransack

左心房为你撑大大i 提交于 2019-12-02 04:03:11
I am developing a rails application using the Ransack gem and below is the code that I have written so far to filter my database which works like a charm. Now what I am trying to do is to add additional button like filter options to my index view (where each button has pre-defined filter value). In other words, once the database is first filtered with a brand name, then I would like users to be able to further filter the database by clicking one of the buttons which has a pre-defined filter value of say 'colour = white', then rails will show all the data with the selected brand name and the

Rails 3.2 and Ransack - Is it possible to pass additional params in a sort_link?

江枫思渺然 提交于 2019-12-01 10:56:17
All is in the title... Using rails 3.2.11 and Ransack all works fine... I added a functionality to let my users choose the number of items to show per page and it works fine too, but I lose the "per_page" choice when I click on the sort_link As I can pass additional params to will_paginate like this <%= will_paginate :params => {:pp => params[:pp]} %> Is there a way to do the same thing with a Ransack sort_link ? Cheers I have found it ! Solution : <th><%= sort_link(@q, :profile_last_name, 'Last name',{:pp => params[:pp]}) %></th> Cheers 来源: https://stackoverflow.com/questions/15272095/rails-3

Rails 3.2 and Ransack - Is it possible to pass additional params in a sort_link?

六眼飞鱼酱① 提交于 2019-12-01 08:42:31
问题 All is in the title... Using rails 3.2.11 and Ransack all works fine... I added a functionality to let my users choose the number of items to show per page and it works fine too, but I lose the "per_page" choice when I click on the sort_link As I can pass additional params to will_paginate like this <%= will_paginate :params => {:pp => params[:pp]} %> Is there a way to do the same thing with a Ransack sort_link ? Cheers 回答1: I have found it ! Solution : <th><%= sort_link(@q, :profile_last

No Ransack::Search object was provided to search_form_for

杀马特。学长 韩版系。学妹 提交于 2019-12-01 07:39:48
I realise other people have asked about this error but it was to do with a different circumstance. I have added the Ransack gem for rails 4 and bundled installed with: gem "ransack", github: "activerecord-hackery/ransack", branch: "rails-4" I have also edited my controller as follows (recipes_controller): def index if params[:tag] @all_recipes = Recipe.tagged_with(params[:tag]) else @all_recipes = Recipe.all end if signed_in? @user_recipes = current_user.recipes.order("created_at DESC").paginate(page: params[:page], :per_page => 10) end if params[:q] @q = Recipe.search(params[:q]) @all_recipes

No Ransack::Search object was provided to search_form_for

谁说胖子不能爱 提交于 2019-12-01 04:58:40
问题 I realise other people have asked about this error but it was to do with a different circumstance. I have added the Ransack gem for rails 4 and bundled installed with: gem "ransack", github: "activerecord-hackery/ransack", branch: "rails-4" I have also edited my controller as follows (recipes_controller): def index if params[:tag] @all_recipes = Recipe.tagged_with(params[:tag]) else @all_recipes = Recipe.all end if signed_in? @user_recipes = current_user.recipes.order("created_at DESC")

Ransack, find record that has all related records

妖精的绣舞 提交于 2019-11-30 18:48:36
I have a recipe model which has_many ingredients and each ingredient belongs to an item. In my advanced search form, I would like a user to select multiple ingredients and let Ransack find a recipe that contains all the ingredients selected by the user. I tried the following searchfield: = f.collection_select(:ingredients_item_id_in, Item.all, :id, :name, {}, {multiple: true}) But logically, this results in all recipes being shown that contain any of the selected ingredients. changing :ingredients_item_id_in to :ingredients_item_id_in_all results in an incorrect Query since one record cannot

How to search array through ransack gem?

巧了我就是萌 提交于 2019-11-30 16:48:35
I'm using ransack gem for searching in rails application. I need to search an array of email_ids in User table. Referring to this issue at ransacking, I followed the steps and added this to the initializers folder ransack.rb Ransack.configure do |config| { contained_within_array: :contained_within, contained_within_or_equals_array: :contained_within_or_equals, contains_array: :contains, contains_or_equals_array: :contains_or_equals, overlap_array: :overlap }.each do |rp, ap| config.add_predicate rp, arel_predicate: ap, wants_array: true end end In the rails console, if i do like this: a = User

Ransack export results to CSV

邮差的信 提交于 2019-11-30 15:46:24
问题 I'm trying to export a list of Ransack (Railscast) results to a CSV file (Railcast). However, it keeps exporting all of the objects, instead of the results returned by the Ransack search. Can anyone tell me where I'm going wrong? In the Reports controller, I've tried passing both @bookings and @search.result: def index @search = current_user.bookings.search(params[:q]) @bookings = @search.result @search.build_condition respond_to do |format| format.html format.csv { render text: Booking.to