If I'm using react-rails for the index, how do I link to the show page? The link below needs the path.
<a href={this.props.post.id}></a>
If it were a Rails template, you might use post_path(post) to generate the link. But since we don't have access to that path from JavaScript, we have to find another solution. The two options I've used are:
jsx
<a href={this.props.postsPath + "/" + this.props.post.id}></a>
/rails/info/routes page to determine what the URL _should_ be, then write it as a string in the JS code. For example:jsx
<a href={"admin/posts/" + this.props.post.id}></a>
I've never tried it, but a third option could be something like JsRoutes, which brings Rails route helpers into JavaScript. If hardcoding is not feasible or too risky, that might be a good solution!
Most helpful comment
If it were a Rails template, you might use
post_path(post)to generate the link. But since we don't have access to that path from JavaScript, we have to find another solution. The two options I've used are:jsx <a href={this.props.postsPath + "/" + this.props.post.id}></a>/rails/info/routespage to determine what the URL _should_ be, then write it as a string in the JS code. For example:jsx <a href={"admin/posts/" + this.props.post.id}></a>I've never tried it, but a third option could be something like JsRoutes, which brings Rails route helpers into JavaScript. If hardcoding is not feasible or too risky, that might be a good solution!