Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to route a static controller in Rails?
    text
    copied!<p>I have a static_controller that is in charge of all the static pages in the site and works as follows in routes.rb:</p> <pre><code>map.connect ':id', :controller =&gt; 'static', :action =&gt; 'show' </code></pre> <p>I have a static page called about that among other information, has a contact form. I currently have a contacts_controller that is in charge of inserting the contact information to the database. Inside my routes.rb file, I have:</p> <pre><code>map.resources :contacts </code></pre> <p>My contact form (simplified) looks like this:</p> <pre><code>&lt;% form_for @contact do |f| %&gt; &lt;p class="errors"&gt;&lt;%= f.error_messages %&gt;&lt;/p&gt; &lt;p&gt; &lt;%= f.label :first_name %&gt; &lt;%= f.text_field :first_name %&gt; &lt;/p&gt; &lt;p class="buttons"&gt;&lt;%= f.submit %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>Which in turn submits to the create action of my contacts_controller. My create action looks like this:</p> <pre><code>def create @contact = Contact.new(params[:contact]) if @contact.save flash[:notice] = "Email delivered successfully." end redirect_to "about" end </code></pre> <p>The problem is, is the that when I redirect back to my about page the error_messages for the form get lost (since the error_messages for the form only exist for one request, and that request ends upon redirect). How would I go about preserving the error_messages and still linking the users back to the about static url? Would a session/flash be sufficient (if so, what code would I use to pass error messages) or am I going about this whole thing wrong?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload