After setup a simple post associated user model with rails i'd like to get the post owner avatar with react but all that i get this error:
TypeError: Cannot read property 'username''avatar' etc.. of undefined
I've tried to get the associated post user on fetching the post
async getPost() {
// this.setState({showProgress: true})
let {
match: { params }
} = this.props;
const response = await axios
.get(`/posts/${params.id}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
credentials: "same-origin"
})
.then(result => {
this.setState({
title: result.data.post.title,
user: result.data.post.user.username,
user: result.data.post.user,
url: result.data.post.user.avatar.post.url
});
})
.catch(error => {
console.error(error);
});
}
but Still showing error on the log and the user that is filled with the post is the user_id
So, someone has any hint to spare about this?
console.log(result)so that it will be easy to debug.