add book view page

This commit is contained in:
2013-01-07 17:50:03 +08:00
parent f8ebded029
commit bab0135c19
4 changed files with 14 additions and 1 deletions
+7 -1
View File
@@ -1,10 +1,16 @@
class BookController < ApplicationController
def view
@book = Book.find_by_id params[:id]
end
def search
unless params[:arg] == nil
@books = Book.where("name like ?","%#{params[:arg]}%")
render json: @books
else
render json: {msg:'wrong'}
end
end
end
+4
View File
@@ -1,2 +1,6 @@
- content_for :javascript_includes do
= javascript_include_tag 'book'
div.detail
h3 =@book.name
img.cover src="#{@book.image}"
+1
View File
@@ -2,6 +2,7 @@ Libr::Application.routes.draw do
root to:'home#index'
match 'books/:id' => 'book#view'
get '/search/book/:arg' =>'book#search'
# The priority is based upon order of creation:
# first created -> highest priority.
+2
View File
@@ -1,4 +1,6 @@
class AddSomeBooks
User.create email:'test@test.com', name:'Test'
User.first.books.create name:'看见', image:'http:\/\/img3.douban.com\/mpic\/s24514758.jpg',isbn:'9787549529322'
User.first.books.create name:'寻路中国', image:'http:\/\/img5.douban.com\/mpic\/s4575849.jpg',isbn:'9787532752805'
User.first.books.create name:'送你一颗子弹', image:'http:\/\/img3.douban.com\/mpic\/s4243447.jpg',isbn:'9787542631664'
end