Skip to content

Instantly share code, notes, and snippets.

@hrishimittal
Last active February 26, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrishimittal/9e8e9d74194a432f99e4d816bc3677c0 to your computer and use it in GitHub Desktop.
Save hrishimittal/9e8e9d74194a432f99e4d816bc3677c0 to your computer and use it in GitHub Desktop.
shopping list items
<%= react_component('Lists', lists: @lists) %>
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>
)
}
});
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