diff --git a/app/assets/javascripts/book.js.coffee b/app/assets/javascripts/book.js similarity index 100% rename from app/assets/javascripts/book.js.coffee rename to app/assets/javascripts/book.js diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b29a06d..17239b0 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,4 +13,52 @@ body { background-color: whiteSmoke; height: 60px; padding-bottom: 0; -} \ No newline at end of file + display: inline-block; + width:100%; + text-align: right; +} +p.title{ + margin-top: 5px; +} + +div.span2{ + text-align: center; + +} + +.cover +{ + position:relative; + -webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; + -moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; + box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; +} +.cover:before, .cover:after +{ + content:""; + position:absolute; + z-index:-1; + -webkit-box-shadow:0 0 20px rgba(0,0,0,0.8); + -moz-box-shadow:0 0 20px rgba(0,0,0,0.8); + box-shadow:0 0 20px rgba(0,0,0,0.8); + top:10px; + bottom:10px; + left:0; + right:0; + -moz-border-radius:100px / 10px; + border-radius:100px / 10px; +} +.cover:after +{ + right:10px; + left:auto; + -webkit-transform:skew(8deg) rotate(3deg); + -moz-transform:skew(8deg) rotate(3deg); + -ms-transform:skew(8deg) rotate(3deg); + -o-transform:skew(8deg) rotate(3deg); + transform:skew(8deg) rotate(3deg); +} + +.cover:hover{ + box-shadow: 3px 3px 12px #999; +} diff --git a/app/controllers/book_controller.rb b/app/controllers/book_controller.rb index 9a5a1f8..9171b2b 100644 --- a/app/controllers/book_controller.rb +++ b/app/controllers/book_controller.rb @@ -1,2 +1,10 @@ class BookController < ApplicationController + + def view + + end + + def search + + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 41e9799..1d5228e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController def index - + @books = Book.order 'id DESC' end end diff --git a/app/models/book.rb b/app/models/book.rb index 8d6e481..017a38a 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,5 +1,7 @@ class Book < ActiveRecord::Base attr_accessible :author, :image, :isbn, :name, :users - has_many :users + has_many :user_to_books + has_many :users, through: :user_to_books + end diff --git a/app/models/user.rb b/app/models/user.rb index 6d2834d..4b78153 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base attr_accessible :email, :name, :books - has_many :books + has_many :user_to_books + has_many :books, through: :user_to_books end diff --git a/app/models/user_to_book.rb b/app/models/user_to_book.rb index f0feb35..6929a19 100644 --- a/app/models/user_to_book.rb +++ b/app/models/user_to_book.rb @@ -1,5 +1,7 @@ class UserToBook < ActiveRecord::Base + attr_accessible :user, :book + belongs_to :user belongs_to :book diff --git a/app/views/book/view.html.slim b/app/views/book/view.html.slim new file mode 100644 index 0000000..121a312 --- /dev/null +++ b/app/views/book/view.html.slim @@ -0,0 +1,2 @@ +- content_for :javascript_includes do + = javascript_include_tag 'book' diff --git a/app/views/home/index.html.slim b/app/views/home/index.html.slim index 09a0111..6c78a3e 100644 --- a/app/views/home/index.html.slim +++ b/app/views/home/index.html.slim @@ -1 +1,8 @@ -p Hello \ No newline at end of file +h3 New Arrival: +div.row-fluid +- @books.each do |book| + div.span2 + div + a href="/books/#{book.id}" + img.cover src="#{book.image}" + p.title =book.name \ No newline at end of file diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index b27e23d..67711bb 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -1,7 +1,7 @@ doctype html html head - title Ocelots + title Libr link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" = stylesheet_link_tag '/bootstrap/css/bootstrap.min.css' = stylesheet_link_tag '/bootstrap/css/bootstrap-responsive.min.css' diff --git a/config/environments/production.rb b/config/environments/production.rb index 80edffe..66377e5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,4 +64,8 @@ Libr::Application.configure do # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + config.assets.precompile << '*.js' + config.assets.precompile << '*.css' + end diff --git a/config/routes.rb b/config/routes.rb index 074f008..1c7d7bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Libr::Application.routes.draw do root to:'home#index' + match 'books/:id' => 'book#view' # The priority is based upon order of creation: # first created -> highest priority. diff --git a/script/add_some_books.rb b/script/add_some_books.rb new file mode 100644 index 0000000..94e839e --- /dev/null +++ b/script/add_some_books.rb @@ -0,0 +1,4 @@ +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' +end \ No newline at end of file