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?"
Related
I am trying to underline words that are dynamically generated by the debug(params) method provided by rails. I have something below, but it obviously does not work, plus what I have below is attempt to try and change the words using methods that I already know about (like the .upcase method). I was hoping to underline the word controller if it appears in the text using only Ruby. Can anyone help me out here?
<%= debug(params) if Rails.env.development? %>
<% if debug(params).include?('controller:') %>
<%= 'controller'.upcase %>
<% end %>
thanks
edit:
I should add that debug(params) is a method defined by RAILS, I was able to do the following which seems even more off, so far the answers have not been correct to what I want to do.
<% if Rails.env.development? %>
<% debug_method = debug(params).split.each do |word| %>
<% if word == 'controller:' %>
<ul><% word.upcase %></ul>
<% end %>
<% end %>
<%= debug_method.join %>
<% end %>
which returns the following text: https://ibb.co/cvnEpw , keep the answers coming in though. I want to get the words in the original box (that's generated by the method to underline the controller word https://ibb.co/jmSm2G).
use <u></u> tag
<%= debug(params) if Rails.env.development? %>
<% if debug(params).include?('controller:') %>
<u><%= 'controller'.upcase %></u>
<% end %>
example here
Provide the css to generate html element:
p { text-decoration: underline; }
Add html elemnt to wrap your words:
<%= debug(params) if Rails.env.development? %>
<% if debug(params).include?('controller:') %>
<p> <%= 'controller'.upcase %> </p>
<% end %>
The answer to the question is below. I had to use the .gsub and .html_safe methods.
<%= debug(params).gsub("controller:", "<u>controller:</u>").html_safe %>
This code keeps the existing html & css generated by rails intact
I'm using rails config gem to set feature flags.
Settings.yml
enable_grading: <%= 'true' == ENV['ENABLE_GRADING'] %>
When I try to hide/show some part of the template based on the feature flag, it responds inconsistently.
<% if Settings.enable_grading %>
<div class='grade_tabs'>
...
</div>
<% end %>
So here, even if Settings.enable_grading is true, the div block is not being rendered. But if I modify this to:
<% if Settings.enable_grading == true %>
<div class='grade_tabs'>
...
</div>
<% end %>
now this starts working!(the content is rendered). This is working if we use some sort of ruby interpolation just before the condition check.
<%= Settings.enable_grading %>
<% if Settings.enable_grading %>
<div class='grade_tabs'>
...
</div>
<% end %>
This is really weird. What is wrong in this code? I was using this gem to set feature flags before also which was working well.
I know this is definitely wrong, but I cannot seem to get sub menu links to work on mobile devices, and other posts suggest edditing the bootstrap.min.js file.
However, since I am using the gem "twitter-bootstrap-rails" I do not know where the file is and even if it would work to change it.
Ideas?
This is my code, omitted some parts.
<%= nav_bar :fixed => :top, :brand => image_tag('logo.png'), :responsive => true do %>
<% if user_signed_in? %>
<%= menu_group :pull => :right do %>
<%= drop_down "Scan" do %>
<%= menu_item "Android", 'http://sasfad' %>
<%= menu_item "iPhone", 'zxing://asfasdf' %>
<% end %>
<% end %>
<% end %>
You can't and you shouldn't edit those files. But you can fork the gem, edit the bootstrap.min.js file and use your forked gem in your Gemfile.
My recommendation is not to use the twitter-bootstrap-rails gem as the only thing it does is adding for you the assets to the asset pipeline.
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 %>
So here is my form
<% remote_form_for([:admin, Page.new]) do |f| %>
<ol>
<li>
<%= f.label(:title) %>
<%= f.text_field(:title) %>
</li>
<li>
<%= f.label(:parent_page) %>
<%= f.select(:parent_page_id, Page.roots.map { |p| [p.title, p.id] }.unshift(["none", nil])) %>
</li>
</ol>
<div class="modal-controls">
<%= submit_tag("Save") %> or <%= link_to_function("cancel", "R.Pages.hideAdd();") %>
</div>
<% end %>
And my action
def create
#page = Page.create(params[:page])
#languages = Language.all
#languages.each do |language|
#page.page_languages.create(:language_id => language.id)
end
For some reason the submitted for does not call the create.js.rjs template, but instead tries to call create.html.erb, do i need some sort of extra setting with the form?
btw i am using rails 2.3.5
I can't remember the exact default behavior in rails, but have you tried putting a respond_to at the end of your controller action:
respond_to(:html, :js)
Hope this helps.
EDIT
I went back to check on the default behavior for Rails in respect to rendering views. Rails favors convention over configuration in this instance. The default behavior is that Rails automatically renders views with names that correspond to actions. You don't need the respond_to any more if you stick to this convention. Here is the documentation.
Just wanted to update my post with the correct info... glad you figured your problem out.
I had named my template create.rjs.js instead of create.js.rjs, thats why i didnt work