score:17

Accepted answer

i don't think the warning has anything to do with the issue but just to get rid of it you can add the key prop in the react component like this:

var posts = react.createclass({

  render: function() {

    var createitem = (p) => (

    <div classname="row" key={p.id}>
      {p.post_type}
      {p.foobar}
      {p.user.name} //this does not work
    </div>

    );

    return (
      <div classname="panel">
        {this.props.posts.map(createitem)}
      </div>
    );

  }
});

as for the real issue, please try changing the assignment of @posts to something like @posts = post.all.includes(:user).as_json(include: { user: { only: [:name] } })

my guess is that you are just querying the posts. by default as_json (the method called when you return json data) does not include associations, therefore you won't get anything on the react side.


Related Query

More Query from same tag