Here is a simple way to implement AJAX pagination using Kaminari gem. Suppose, We are having a Product Model with fields id and name. So, In the ProductsController , def index @products = Product.all.page(params[:page]).per(params[:per]) respond_to do |format| format.js format.html end end in view file index.html.haml #products = render 'products' #paginator = paginate @products, :remote => true And create _products.html.haml (this will be rendered from index) with content %table @products.each do |product| %tr %td= product.name Finally, We have to create one more file _index.js.haml with content $('#products').html("#{escape_javascript(render 'products')}"); $('#paginator').html("#{escape_javasc...
This can be done only with a custom method validation, Such as class Comment include Mongoid::Document include Mongoid::Timestamps include ActiveModel::Validations validate :must_be_friends def must_be_friends errors.add(:base, 'Must be friends to leave a comment') if hash[:firstname].nil? end end
We can do class_eval & instance_eval using following syntax, In this example, class_eval? method can be accessed my any objects of the String class. Where as instance_eval? method can be accessed by only String class. More clearly, class_eval creates instance methods, but instance_eval creates class methods or it can be applied to only one object at a time. [3] pry(main)> String.class_eval? NoMethodError: undefined method `class_eval?' for String:Class Did you mean? class_eval from (pry):3:in `<main>' [4] pry(main)> String.instance_eval? => true [5] pry(main)> String.new.class_eval? => true my_string = "This is a string" For example you can simply do like below as any string is an object of String Class [5] pry(main)> my_string .class_eval? => true But you can not do [7] pry(main)> my_string.instance_eval? NoMethodError: undefined method `instance_eval?' for "This is a string":String ...
Comments
Post a Comment