Skip to content

Commit

Permalink
Use jbuilder but it gets an error
Browse files Browse the repository at this point in the history
  • Loading branch information
jq-jay committed Apr 7, 2015
1 parent 4a59628 commit 508d581
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -14,3 +14,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

.ruby-version
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -48,3 +48,7 @@ end
gem 'react-rails', '~> 1.0.0.pre', github: 'reactjs/react-rails'

gem 'rails_12factor', group: :production

group :development do
gem 'pry-byebug'
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Expand Up @@ -39,14 +39,21 @@ GEM
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.7.0)
columnize (0.8.9)
connection_pool (2.0.0)
debugger-linecache (1.2.0)
erubis (2.7.0)
execjs (2.0.2)
hike (1.2.3)
Expand All @@ -61,10 +68,18 @@ GEM
libv8 (3.16.14.7)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.4.3)
minitest (5.4.3)
multi_json (1.10.1)
pg (0.17.1)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.0.1)
byebug (~> 3.4)
pry (~> 0.10)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand Down Expand Up @@ -102,6 +117,7 @@ GEM
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
slop (3.6.0)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -131,6 +147,7 @@ DEPENDENCIES
jbuilder (~> 1.2)
jquery-rails
pg
pry-byebug
rails (= 4.1.8)
rails_12factor
react-rails (~> 1.0.0.pre)!
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/comments_controller.rb
@@ -1,13 +1,14 @@
class CommentsController < ApplicationController
def index
@presenter = {
:comments => Comment.last(5),
:form => {
:action => comments_path,
:csrf_param => request_forgery_protection_token,
:csrf_token => form_authenticity_token
}
}
@comments = Comment.last(5)
# @presenter = {
# :comments => Comment.last(5),
# :form => {
# :action => comments_path,
# :csrf_param => request_forgery_protection_token,
# :csrf_token => form_authenticity_token
# }
# }
end

def create
Expand Down
6 changes: 3 additions & 3 deletions app/views/comments/index.html.erb
@@ -1,3 +1,3 @@
<%= react_component('CommentBox',
{:presenter => @presenter.to_json, :imgSrc => image_path("gundam.jpg")},
{:prerender => true}) %>
<h1>Comments</h1>

<%= react_component 'CommentBox', render(template: 'comments/index.json.jbuilder'), {prerender: true} %>
11 changes: 11 additions & 0 deletions app/views/comments/index.json.jbuilder
@@ -0,0 +1,11 @@
json.presenter do
json.comments(@comments) do |comment|
json.extract! comment, :id, :author
end
json.form do
json.action comments_path
json.csrf_param request_forgery_protection_token
json.csrf_token form_authenticity_token
end
end
json.imgSrc image_path("gundam.jpg")
9 changes: 4 additions & 5 deletions config/database.yml
Expand Up @@ -13,18 +13,17 @@
development:
adapter: postgresql
encoding: unicode
database: myapp_development
database: sample_react_rails_app_development
pool: 5
password:

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
adapter: postgresql
encoding: unicode
database: sample_react_rails_app_test
pool: 5
timeout: 5000

production:
adapter: sqlite3
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
@@ -1,4 +1,7 @@
SampleReactRailsApp::Application.routes.draw do

resources :comments
root :to => redirect("/comments")

# resource :top, controller: :top, only: :show
end

0 comments on commit 508d581

Please sign in to comment.