spec/fake_app.rb in action_args-1.0.1 vs spec/fake_app.rb in action_args-1.0.2
- old
+ new
@@ -38,11 +38,12 @@
render text: @author.name
end
end
class BooksController < ApplicationController
# optional parameter
- def index(page = 1)
- @books = Book.limit(10).offset((page.to_i - 1) * 10)
+ def index(page = 1, q = nil)
+ @books = Book.limit(10).offset(([page.to_i - 1, 0].max) * 10)
+ @books = @books.where('title like ?', "%#{q}%") unless q.blank?
render text: 'index'
end
def show(id)
@book = Book.find(id)