Last active
February 26, 2017 22:19
-
-
Save hrishimittal/9e8e9d74194a432f99e4d816bc3677c0 to your computer and use it in GitHub Desktop.
shopping list items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= react_component('Lists', lists: @lists) %> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Lists = React.createClass({ | |
render: function() { | |
return ( | |
<div> | |
<h1>My shopping lists</h1> | |
{this.props.lists.map(function(list) { | |
return ( | |
<div key={list.id}> | |
<h3>{list.name}</h3> | |
<i>{list.description}</i> | |
{list.items.map(function(item) { | |
return ( | |
<p key={item.id}>{item.name}</p> | |
) | |
})} | |
</div> | |
) | |
})} | |
</div> | |
) | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListsController < ApplicationController | |
def index | |
@lists = List.includes(:items).map { |list| list.as_json.merge({items: list.items.as_json}) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment