2015-06-22 57 views
1

我一直在Ruby on Rails中做一個項目,我需要你的幫助。到目前爲止,我已經設法創建了一個非常基本的博客,可以創建,閱讀,更新和刪除博客文章。也可以對特定的帖子發表評論。然而,我一直在嘗試一些bootstraps,看起來好像我找不到有關如何在Rails 4.0或更高版本的現有Rails項目中使用它的更新文章。更改現有Rails應用程序的佈局

現在我真的只想添加一個佈局到應用程序,但它甚至可以不使用引導程序?這裏是的Gemfile:

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.1' 
# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more:  https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use Unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

group :development, :test do 
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console 
    gem 'byebug' 

    # Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 

這裏是application.html.er:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Blog</title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

<%= yield %> 

</body> 
</html> 

這裏是application.css:

*= require_tree . 
*= require_self 

在我的樣式表文件夾中我得到的文件comments.scss,posts.scss,scaffolds.scss。但我的大問題是,接下來我要做什麼來改變應用程序的設計?

回答

0

您的應用程序的視圖主要是html + css。你處理視圖上的html,並處理資產上的css文件。

我假設你已經加載CSS文件comments.scss, posts.scss, scaffolds.scss,因爲你加入他們app/assets/stylesheets和你app/assets/stylesheets/application.css您有:

*= require_tree . 

,這將需要樹

下一步中添加文件要更新您的視圖,首先編輯application.html.erb的佈局文件,並使用您導入的css文件的預期樣式和結構,然後更新每個視圖以添加所需的類。

如果你已經不知道基本的html/css以及它是如何工作的,請花些時間閱讀它,並構建一些自定義的.html和.css文件(在rails或ruby代碼中沒有任何ruby),因爲在以Ruby結束您最終做的是爲.html文件構建動態內容並編譯您的.css文件以使加載速度更快,編輯更容易。

+0

好的,謝謝!但是,甚至可以在不添加任何引導程序的情況下使用html/css獲得美觀的視圖? – Nitram

+0

是的,引導它只是一個快速演示或構建網站的框架,而不會花費太多時間在HTML/CSS – rorra