I understand Kaminari perform well with Rails3 reading this article: Rails 3 pagination, will_paginate vs. Kaminari, but how about with Rails4? Also, when stylizing them with Bootstrap3, which gem is easier solution?
In my experience, there is very little difference between Kaminari & Will Paginate - it's mainly a personal choice as to which you use (rather like Paperclip / Carrierwave or Mac / Windows)
In terms of compatibility, both gems work natively with Rails 4
Bootstrap
In reference to Bootstrap, I think you're asking the wrong question
Bootstrap is a CSS framework, which has no bearing on the backend functionality of your app
Bottom line is you're going to have to call the pagination methods from your controller, and so the differences of the systems will only be cosmetic. If you use Bootstrap to stylize them, you'll have to do the same with either gem
So the choice is yours!
It is pretty easy to implement twitter bootstrap pagination with Kaminari. Just follow the steps below:
Add gem 'kaminari' to your GemFile. Run bundle install and restart rails server
Check the Kaminary themes - in your case you need the bootstrap3 theme
Run rails g kaminari:views bootstrap3
That's it.
Kaminari works fine for me with Rails 4.1.5
You can get it working with Bootstrap 3 by changing one line of code in the generated Bootstrap theme for Kaminari
In Views/Kaminari/_paginator.html.erb
Change this line: <div class="pagination"><ul>
To this: <ul class="pagination pagination-lg">
..and get rid of the div; just use the ul above --works fine for me.
Here is the code for the whole partial:
<%= paginator.render do %>
<ul class="pagination pagination-lg">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? %>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
<% end %>
Related
I updated Rails to 5.2 version with ActiveStorage
Everything works fine, but when I perform a loop through my model attached files in order to display them as bootstrap cards, I see my files attributes on the page.
I don't want it to display anything.
How can I prevent that?
<strong style="margin: 10px">Files :</strong>
<div class="card-columns">
<%= #mymodel.files.each do |file| %>
<% end %>
</div>
what it makes on my page
Remove the = from your loop header...
Instead of
<%= #mymodel.files.each do |file| %>
Use
<% #mymodel.files.each do |file| %>
Checkout what the difference is
I wanted to add some pagination to my rails project.
I've already added Kaminari and I've managed to display only 10 records per page. But I'm already missing the next/prev arrow and the page indicator.
I'm using Kaminari.paginate_array(#array).page(params[:page]).per(10)
This is the only thing I've added until now.
I don't know if it's important, but in my view I have #array.to_json
What should I add to display the arrows?
View code:
<% content_for :create_button do %>
<%= create_button(new_battery_reset_path) %>
<% end %>
<div class="tab-content">
<%= paginate #battery_resets %>
<div class="tab-pane active" id="battery-resets" role="tabpanel"
data-battery-resets='<%= #battery_resets.to_json %>'>
</div>
<div class="tab-pane" id="profile" role="tabpanel">...</div>
<div class="tab-pane" id="messages" role="tabpanel">...</div>
</div>
controller code:
def index
#battery_resets = Kaminari.paginate_array(BatteryResetDecorator.build_collection(
::Filters::BatteryReset.new(
current_account.battery_resets.includes({ device: :account },
:device_inspection)
).apply(permited_params[:q])
)).page(params[:page]).per(10)
respond_with(#battery_resets)
end
You might want to put <%= paginate #array %> in your rails view.
Also try to read gem's wiki first before asking any questions.( kaminari wiki )
Per the docs:
Just call the paginate helper:
<%= paginate #battery_resets %>
This will render several ?page=N pagination links surrounded by an
HTML5 <nav> tag.
This is the same pattern for will_paginate (another gem) also.
--
In regards your fa_icon error, that's caused by the font-awesome-rails gem; it means the helper is not available.
The way to fix it is to make sure you're only using the bundled files with Kaminari. If you've changed _next_page.html.erb in any way, the error is likely coming back now.
--
The quick fix for the fa_icon error is to add font-awesome-rails to your Gemfile:
#Gemfile
gem "font-awesome-rails"
I am having an issue with carrierwave/active-record in my rails application. My problem is that the following code resolves all of the images to null
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= ad.carrier_image.url %>" >
<% end %>
Where as the following renders all the images just fine
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= Ad.find(ad.id).carrier_image.url %>" >
<% end %>
The urls are there, just on the initial loop the carrier_image does not seem to be preloaded into the active record objects I think this is an issue with my understanding of rails eager loading, but I am having trouble figuring out how one would avoid this issue
What happens when you use the rails image_tag helper? You're also missing the brackets off the url call as per the carrierwave documentation, but I don't think that's what's causing you drama.
<%= image_tag ad.carrier_image_url() %>
As a side note, you should really move the "Ad.all.limit(30)" out of your view if you wish to keep it all "railsy".
I have a trouble with kaminari pagination and bootstrap styles.
Pagination works fine, but styles are broken.
Is there any way to fix it? or is there any other style sheets for kaminari pagination?
here is a screenshot http://imageshack.us/photo/my-images/59/kaminari.png/
Browser Google Chrome
= paginate #activities, :theme => 'twitter-bootstrap'
You can also run
rails g kaminari:views bootstrap
This might be due to missing i18n translations -- they create extra tags which messes up bootstrap pagination.
checkout https://github.com/gabetax/twitter-bootstrap-kaminari-views
I've had the same problem and after some experimentation I ended up with this in my gem file;
gem "kaminari", "~> 0.13.0"
gem "kaminari-bootstrap", "~> 0.1.2"
The page links are working the way I think they are supposed to, although I dont like the way they look.
I get an error message if I use Kaminari 0.14.0, so back it off to 0.13.0.
Also...
I noticed it messes things up if I generate Kaminari views. It is the most stable to use the views that come with the gem, if you can live with them.
If you're using Bootstrap 3 you'll need to do the following. In the console:
rails g kaminari:views bootstrap
Then, replace the contents of app/views/kaminari/_pagination.html.erb with the following:
<%= paginator.render do %>
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? %>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
<% end %>
Replace app/views/_first_page.html.erb with the following (note the change to the class of li and from link_to_unless to link_to):
<li <%= "class=disabled" if current_page.first? %>>
<%= link_to raw(t 'views.pagination.first'), url, :remote => remote %>
</li>
Also replace the contents of _prev_page, _last_page, and _next_page in a similar fashion (you'll just need to change "current_page.first?" to "current_page.last?"
Running RUby 1.9.3-p194 and Rails 3.2.3 and the latest paperclip gem.
I am following the tutorial here:
Multiple File Uploads with Paperclip & Rails 3 (Screencast)
I've set up a post to have multiple images. And I build 5 image objects in my controller.
However, this does not appear to show up in my view:
<% f.fields_for(:postimages) do |asset_fields| %>
<p><%= asset_fields.file_field :image %></p>
<% end %>
Any ideas on what I'm doing wrong?
Pretty sure you need an = on that first line, so
<%= f.fields_for(:postimages) ... %>