You should use the will_paginate gem for pagination.
Steps :
1. Create new project
Develop > rails new addpagination
2. Open the gemfile inside the project folder (addpagination).Add below line in gemfile
gem 'will_paginate', '~> 3.0'
3. Enter below command in terminal and execute.
Develop > bundle install
4. Create the Database
Develop > rake db:create
5. Create the form using scaffolding
Develop > rails g scaffold post name:string city:string
6. Migrate the table
Develop > rake db:migrate
7. Now run the application
Develop > rails s
8. Check the application.Its working or not.
open browser and enter http://localhost:3000/
9. Configure the page redirection in routes.rb inside the config folder
root 'posts#index'
10. Now add the value into the form.
11. Open the posts_controller.rb
def index #@posts = Post.all @posts = Post.paginate(:page => params[:page], :per_page => 3) end # @posts = Post.all - comment this line # @posts = Post.paginate(:page => params[:page], :per_page => 3) - Add this line to index function
12. Add below line to index.html.erb
<%= will_paginate @posts %>
<%= link_to 'New Post', new_post_path %>
It was really a nice post and i was really impressed by reading this Ruby on Rails Online Training Hyderabad
ReplyDeleteشركة صيانة افران بالمدينة المنورة
ReplyDeleteعزل اسطح بجدة