2016年7月8日 星期五

[Rails]將Database 資料傳送給Javascript 使用,使用Gon

Gemfile
gem 'gon'

application.html.erb
<%= include_gon %>

pages_controller.rb
def index
     gon.db = Page.all
...

回到console
bundle install
rails s

in AWS
RAILS_ENV=production bundle install

則可以在index頁面的Console中輸入gon.db 會得到Objects array

references
[1]Passing data to Javascript