Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access validation messages in partials?
    primarykey
    data
    text
    <p>So, each rails project i seem to run into this problem and would be really grateful if someone could enlighten me:</p> <p>With a "normal" setup when the form sits on the view immediately associated with the url/controller it is pretty straightforward, a <code>render =&gt; :action</code> on fail will display the validation message.</p> <p>Now what i have is a form in a partial sitting on a page whose url/controller is a show/:id and not the create action of the form, the validation kicks in but i cannot get the validation message to display because i can't trigger the correct render action... CLosest i got is a render => @object but there is no css/layout, i can pass a message through a redirect with flash[] but it feels wrong, same with jquery/client error messages...</p> <p>So how can i "cleanly" display validation messages of a form in a partial (under another controller/action than the parent page)?</p> <p>(thanks in advance for your help)</p> <p>edit: can't paste the actual thing now but i'll do my best to explain</p> <p>i have a main page e.g. article/show/01, on this page is the content of the article (@article) and then at the bottom of the page is a partial _commentform with a form to post a comment. This form is bound to a Create action of a different controller (comments controller).</p> <p>Now if the form were on its own "page"/url instead of a partial, say /comment/create, i would jus do:</p> <pre><code>if @comment.save redirect_to @comment else render =&gt; :create end </code></pre> <p>and the validation would display normally.</p> <p>In my case the form is in a a partial on the article/show/01 url, what should be the equivalent to the code above so that on validation fail error messages are displayed on the parent url, like "render article/show/01" ? I am sure it is easy but i cannot get it to work (i just can redirect on success but cannot display the errors with a render)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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