over 4 years ago

在Cloud IDE跑的時候用這個
bundle install --without production

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

啟動伺服器
rails server -b $IP -p $PORT

改說名檔檔名
git mv README.rdoc README.md

<!--[if lt IE 9]>
  <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
  </script>
<![endif]-->

使用http下載東西~
curl -O http://rubyonrails.org/images/rails.png

因為我們使用image_taghelper,Rails會自動到下列資料夾找圖
app/assets/images/

寫CSS
touch app/assets/stylesheets/custom.css.scss
include the entire Bootstrap CSS framework in the file

@import "bootstrap-sprockets";
@import "bootstrap";

<%= render 'layouts/shim' %>
app/views/layouts/_shim.html.erb

Test

$ rails generate integration_test site_layout
      invoke  test_unit
      create    test/integration/site_layout_test.rb

Only run integration test
rake test:integration

First Header Second Header
assert_select "div" <div>foobar</div>
assert_select "div", "foobar" <div>foobar</div>
assert_select "div.nav" <div class="nav">foobar</div>
assert_select "div#profile" <div id="profile">foobar</div>
assert_select "div[name=yo]" <div name="yo">hey</div>
assert_select "a[href=?]", ’/’, count: 1 <a href="/">foo</a>
assert_select "a[href=?]", ’/’, text: "foo" <a href="/">foo</a>
  test "should be valid" do 
    assert @user.valid?
  end
  
  test "name should be present" do
    @user.name = "   "
    assert_not @user.valid?
  end

validates(:name, presence: true) = validates :name, presence: true
user.errors.full_messages

資料驗證
validates :email, format: { with: /<regular expression>/ }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

← Heroku commands and tips RailsFun 1st class (Ruby 1) →
 
comments powered by Disqus