B
B
Breezy
Search…
Rails

Setting the content location

On non-GET visits, Superglue uses the response's content-location to create the key used to store your props.
This is because when you render in a create or update, the returned response does not necessarily reflect the url the user should see.
For example, when the user is on posts/new and they make a POST request to posts/, we may decide to render posts/new for any errors you'd like to show.
It is recommended that you set this header in your create and update methods. If you used the generators, this is done for you.
1
def create
2
@post = Post.new(post_params)
3
4
if @post.save
5
redirect_to @post, notice: 'Post was successfully created.'
6
else
7
response.set_header("content-location", new_post_path)
8
render :new
9
end
10
end
Copied!

Rails Flash

Your Rails flash will work as expected. On the React side, you receive the flash in the props of your connected component:
1
class PostsIndex extends React.Component {
2
render () {
3
const {
4
flash,
5
} = this.props
6
7
...
8
}
9
}
10
11
export default connect(
12
mapStateToProps,
13
mapDispatchToProps
14
)(PostsIndex)
Copied!
?> When using data-bz-visit, all flash in Superglue's redux state will be cleared before the request.
?> When using data-bz-remote, the recieved flash will be merged with the current page's flash.

redirect_back_with_props_at

A helper to help retain the props_at parameter as part of the redirect location. This helper has the same method signature as Rails own redirect_back.
1
def create
2
redirect_back_with_props_at fallback_url: '/'
3
end
Copied!

props_from_form_with

A view helper that will give you the camelized attributes generated by form_with that can be used to passed to React. Has the same method signature as form_with
1
json.form_props props_from_form_with(
2
url: venue_floor_seats_path(venue, floor),
3
method: :get,
4
)
Copied!
Last modified 16d ago