> For the complete documentation index, see [llms.txt](https://jho406.gitbook.io/breezy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jho406.gitbook.io/breezy/dev/api/rails.md).

# Rails

## Setting the content location

On non-GET `visit`s, Breezy 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.

```ruby
def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to @post, notice: 'Post was successfully created.'
  else
    response.set_header("content-location", new_post_path)
    render :new
  end
end
```

## Rails Flash

Your Rails flash will work as expected. On the React side, you receive the flash in the `props` of your connected component:

```
class PostsIndex extends React.Component {
  render () {
    const {
      flash,
    } = this.props

    ...
  }
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(PostsIndex)
```

{% hint style="info" %}
When using `data-bz-visit`, all flash in Breezy's redux state will be cleared before the request.
{% endhint %}

{% hint style="info" %}
When using `data-bz-remote`, the recieved flash will be merged with the current page's flash.
{% endhint %}

## `redirect_back_with_bzq`

A helper to help retain the `bzq` parameter as part of the redirect `location`. This helper has the same method signature as Rails own `redirect_back`.

```ruby
def create
  redirect_back_with_bzq fallback_url: '/'
end
```

## 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`

```ruby
json.form_props props_from_form_with(
  url: venue_floor_seats_path(venue, floor),
  method: :get,
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jho406.gitbook.io/breezy/dev/api/rails.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
