Note that there are some explanatory texts on larger screens.

plurals
  1. POValidations with Simple Form
    primarykey
    data
    text
    <p>I'm attempting to use the simple_form gem in order to create forms. I'm also using twitter bootstrap for styling, so there are certain cases where simple_form is too rigid to do what I want to do (not always).</p> <p>I'm submitting a form that should fail on validation, which it does. However, when it renders the page again, it doesn't display error messages near the input, and the page only half renders.</p> <p><strong>Controller Code</strong>: (note, I'm essentially using show/edit action as the same thing)</p> <pre><code>def update @contact = current_resource authorize! :update, @contact respond_to do |format| if @contact.update_attributes(params[:customer_relationship_contact]) format.html { redirect_to customer_relationship_contact_url(@contact), notice: "#{@contact.to_s} was successfully updated." } format.json { head :no_content } else format.html { render :edit } format.json { render json: @contact.errors, status: :unprocessable_entity } end end end def show @contact = current_resource authorize! :show, @contact respond_to do |format| format.html # show.html.erb format.json { render json: @contact } end end </code></pre> <p><strong>View/Form Code</strong>:</p> <pre><code>&lt;%= simple_form_for @contact, :html =&gt; {:novalidate =&gt; true} do |f| %&gt; &lt;%= f.error_notification %&gt; &lt;fieldset&gt; &lt;legend&gt;Contract&lt;/legend&gt; &lt;div class="controls controls-row"&gt; &lt;div class="span3"&gt; &lt;div class="controls controls-row"&gt; &lt;%= f.label :tax_id_number, 'Social Security No.' %&gt; &lt;%= f.text_field :tax_id_number, class: 'span12', placeholder: 'Social Security No.' %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;div class="form-actions"&gt; &lt;%= f.button :submit, :class =&gt; 'btn-primary' %&gt; &lt;%= link_to "Cancel", customer_relationship_contacts_path, :class =&gt; 'btn' %&gt; &lt;/div&gt; </code></pre> <p><strong>Model Validation</strong>:</p> <pre><code> validates :tax_id_number, format: { with: /\A[0-9]+\z/, message: "Please enter only numbers without dashes." }, allow_blank: true </code></pre>
    singulars
    1. This table or related slice is empty.
    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