Skip to content

Commit

Permalink
Creating 'Record' and 'Records' components. Displaying records
Browse files Browse the repository at this point in the history
  • Loading branch information
fervisa committed May 16, 2015
1 parent 9b32481 commit bf1d80c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/components/record.js.coffee
@@ -0,0 +1,6 @@
@Record = React.createClass
render: ->
React.DOM.tr null,
React.DOM.td null, @props.record.date
React.DOM.td null, @props.record.title
React.DOM.td null, amountFormat(@props.record.amount)
21 changes: 21 additions & 0 deletions app/assets/javascripts/components/records.js.coffee
@@ -0,0 +1,21 @@
@Records = React.createClass
getInitialState: ->
records: @props.data
getDefaultProps: ->
records: []
render: ->
React.DOM.div
className: 'records'
React.DOM.h2
className: 'title'
'Records'
React.DOM.table
className: 'table table-bordered'
React.DOM.thead null,
React.DOM.tr null,
React.DOM.th null, 'Date'
React.DOM.th null, 'Title'
React.DOM.th null, 'Amount'
React.DOM.tbody null,
for record in @state.records
React.createElement Record, key: record.id, record: record
2 changes: 2 additions & 0 deletions app/assets/javascripts/utils.js.coffee
@@ -0,0 +1,2 @@
@amountFormat = (amount) ->
'$ ' + Number(amount).toLocaleString()
3 changes: 3 additions & 0 deletions app/controllers/records_controller.rb
@@ -1,2 +1,5 @@
class RecordsController < ApplicationController
def index
@records = Record.all
end
end
1 change: 1 addition & 0 deletions app/views/records/index.html.erb
@@ -0,0 +1 @@
<%= react_component 'Records', { data: @records } %>

0 comments on commit bf1d80c

Please sign in to comment.