will-paginate

rails3 will_paginate hash object

混江龙づ霸主 提交于 2019-12-18 17:54:31
问题 Looks like will_paginate dosen't support paginating a hash object. I have a list of articles which is basically a collection of yaml files that i want to output on a page. def index @articles = Dir["#{Rails.root}/blog_articles/*.yml"].inject({}) do |h, file| h["#{File.basename(file, '.yml')}"] = YAML::load(File.open(file)) h end end Can anyone suggest me on how to write the pagination for this? Thanks. 回答1: In your controller: def index @articles = Dir["#{Rails.root}/blog_articles/*.yml"]

Combine arrays of conditions in Rails

社会主义新天地 提交于 2019-12-18 03:47:29
问题 I'm using the Rails3 beta, will_paginate gem, and the geokit gem & plugin. As the geokit-rails plugin, doesn't seem to support Rails3 scopes (including the :origin symbol is the issue), I need to use the .find syntax. In lieu of scopes, I need to combine two sets of criteria in array format: I have a default condition: conditions = ["invoices.cancelled = ? AND invoices.paid = ?", false, false] I may need to add one of the following conditions to the default condition, depending on a UI

How do I paginate a hash of arrays using the Kaminari (or will_paginate) gem

允我心安 提交于 2019-12-14 04:27:06
问题 I've managed to find a workaround to this now. The index action now has an "order" clause before the call to page and the meals are then sorted and grouped by date. The hackey bit next: @total_pages and @pages are used in the view to provide pagination links as the built-in helper for this does not work with the Hash of arrays as returned by @meals. It works (kind of) but it is hackey. Moving the view stuff into a helper would definitely help clean it up, which is my next step. def index

undefined method `paginate' for Array on Rails 3 with mongoid

耗尽温柔 提交于 2019-12-13 18:25:12
问题 Trying to use will_paginate gem. My Gem file has: gem 'will_paginate', '~> 3.0.0' My orders_controllers.rb: def index @orders = Order.all.paginate(:page => params[:page], :per_page => 20) respond_to do |format| format.html # index.html.erb format.json { render json: @orders } end end On my index.html.erb I've put: <%= will_paginate @orders %> Error: NoMethodError in OrdersController#index undefined method `paginate' for #<Array:0x007f79a1be62f8> Rails.root: /home/askar/Dropbox/rails_studio

will_paginate: how to build a “next page” link?

青春壹個敷衍的年華 提交于 2019-12-13 17:48:51
问题 I know this must be REALLY simple but after looking around I cannot find the answer. I'm using the will_paginate plugin and I like to have a simple "next page" link instead of the whole will_paginate link collection. How can I do this? Thanks! 回答1: This will give you just a simple next button to work with. protected # Tells WP how to render the "Next Page" link def next_page # The only difference from the default here is we renamed the link to "More" # and added a custom class, twitter

how to get paginate to work instead of getting redirected to 'public/index.html'?

痴心易碎 提交于 2019-12-13 06:26:21
问题 I have my homepage using 'public/index.html' which overrides everything from what I've read here. As a result, I have all signed-in users to be redirected to http://localhost:3000/home which I have defined as get '/home' => 'static_pages#home', :as => :home in my routes The problem I'm facing is that on the main page of signed-in users (/home), there's pagination. When I try to click on page 2 http://localhost:3000/?page=2 , it gets sent to public/index.html. I tried the link http://localhost

Rails Minitest integration test broken: Expected at least 1 element matching “div.pagination”, found 0

强颜欢笑 提交于 2019-12-13 05:27:11
问题 We are using Michael Hartl's Rails Tutorial as an inspiration to build a completely different RoR app. However, we stumbled upon an issue that may be of help to other people following the tutorial. Here is our user_index_test.rb file: test "index as admin including pagination and delete links" do log_in_as(@admin) get users_path assert_select 'div.pagination' first_page_of_users = User.paginate(page: 1) first_page_of_users.each do |user| assert_select 'a[href=?]', user_path(user), text: user

Error in Ajax tabs when using endless scroll with Rails' will_paginate

為{幸葍}努か 提交于 2019-12-13 05:14:40
问题 TL;DR My AJAX tabs are not working together with my implementation of endless scrolling (will_paginate). Details I have a page that has ajax tabs that loads different actions in my controller to render a partial with different content. So the "popular-view" has +two remote: true links at the top. They work fine. They render the corresponding partial appropriately using the respond_to js. The problem is that I'm also paginating these partials with will_paginate (endless scrolling like ryan

Will Paginate: Limit number of results

可紊 提交于 2019-12-12 12:25:19
问题 Im using the will paginate gem for ruby. I am using will paginate to get a bunch of people and sorting on a field. What I want is only the first 100 of those. Essentially the top people. I cant seeem to do this. How would i go about it? Thanks 回答1: people = Person.limit(100).paginate(:per_page => 5) 回答2: As far as my knowledge goes will_paginate doesn't provide an option for this, I just had a root around in its source too to check, but if you don't mind having a subquery in your conditions

Infinite scroll rails ajax request firing, but not displaying next paginated page

人盡茶涼 提交于 2019-12-12 05:49:26
问题 I have a rails app that I am using will_paginate for. I am then using will_paginate as a basis for infinite scroll. After a lot of trial and error, the request seems to be working, but instead of rendering the next page of content in the app, the request is re-rendering all of my content and displaying it in paginated form again. I have a thought that it is to do with my .each iterator in my partial, but I am not sure exactly. Below is my partial, controller, js.erb, coffescript, and logs. If