mirror of
https://github.com/wahyd4/Libr.git
synced 2026-08-09 04:46:07 +10:00
add book view page
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
- content_for :javascript_includes do
|
||||
= javascript_include_tag 'book'
|
||||
|
||||
div.detail
|
||||
h3 =@book.name
|
||||
img.cover src="#{@book.image}"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user