常見的 Ruby on Rails 工程師面試問題
收錄一些業界常見/常問的面試問題和翻譯解答
解答不見得完整和精確,但在面試的環境下回答應該是足夠的
有需要改正或有什麼要新增 / 補充的地方也請大家發 PR
常見的 Ruby on Rails 工程師面試問題
收錄一些業界常見/常問的面試問題和翻譯解答
解答不見得完整和精確,但在面試的環境下回答應該是足夠的
有需要改正或有什麼要新增 / 補充的地方也請大家發 PR
URI.split (returning this error), I don't know if this helps you, but I will post here some warnings for also someone else having this error:URI.encode(url) before URI.parse (to avoid special characters)strip to the string you pass to URI.parse (to avoid leading and trailing whitespaces).uri = URI.parse(URI.encode(url.strip))
:binary:boolean:date:datetime:decimal:float:integer:bigint:primary_key:references:string:text:time:timestamp:hstore:json:array:cidr_address:ip_address:mac_address<%= form_for @some_model, :remote => true, :authenticity_token => true do |f| %>
<% end %>
config.action_view.embed_authenticity_token_in_remote_forms = true
官方解釋
config.action_view.embed_authenticity_token_in_remote_forms allows you to set the default behavior for authenticity_token in forms with remote:
true. By default it's set to false, which means that remote forms will not include authenticity_token, which is helpful when you're fragment-caching the form. Remote forms get the authenticity from the meta tag, so embedding is unnecessary unless you support browsers without JavaScript. In such case you can either pass authenticity_token: true as a form option or set this config setting to true.import urllib2,os,hashlib; h = '261dd1222b4693ce6d4f85f9c827ac06' + '6d5ab8ebdd020086947172a8a1356bb6'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')2-3 重開
git init
echo "public/uploads" >> .gitignore
echo "tmp" >> .gitignore
echo "logs" >> .gitignore
git add .
git commit -m "initial commit"
.gitignore 檔案是什麼,並解釋為什麼要忽略某些檔案被傳上去。gem 'sqlite3'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
bundle install --without production 命令來解決軟體相依問題。Gemfile 加入 rails_12factor,讓我們的 app 可以出現在 Heroku。Gemfile 的內容:group :production do
gem 'pg'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
bundle 命令,接著將 Gemfile.lock 提交到妳的程式碼倉庫 (repository):git commit -a -m "Added rails_12factor gem and updated Gemfile.lock"
heroku create,在 Heroku 上產生一個新的 Heroku app,妳會看到像是下面的訊息:Creating evening-sky-7498... done, stack is cedar
http://evening-sky-7498.herokuapp.com/ | git@heroku.com:evening-sky-7498.git
Git remote heroku added
git push heroku master。妳會看到像是下面的輸出:Counting objects: 134, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (115/115), done.
Writing objects: 100% (134/134), 35.29 KiB, done.
Total 134 (delta 26), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.2
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Fetching gem metadata from https://rubygems.org/.......
...
-----> Launching... done, v4
http://evening-sky-7498.herokuapp.com deployed to Heroku
heroku run rake db:migrate。heroku open 來開啟網頁。form_for這個Helper。它的好處在於透過傳入Model物件,可以在修改的時候自動幫你將預設值帶入。例如我們已經在Part1使用過的event表單:<%= form_for @event do |f| %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
form_tag這個方法。例如:<%= form_tag "/search" do %>
<%= text_field_tag :keyword %>
<%= submit_tag %>
<% end %>
form_for有些類似,但是其中不需要傳Block變數f,其中的欄位Helper需要多加_tag結尾。不像form_for的欄位名稱一定要是Model的屬性之一,在form_tag之中的欄位名稱則完全不受限。gem 'instagram_api'https://github.com/caseyscarborough/instagram 無使用到
gem install instagram