title: Simple_form required field does not work - Ruby on Rails
body: <p>I have a submiting form in a RoR app, built with simple_form. When the fields are blank, the app still goes to the next step without prompting an error or warning. The fields are supposed to be by default <code>required: true</code>; but even writing it manually does not work.</p>
  
  <p>The app has 3 steps: NewPost (new view) -> Preview (create view) -> Post.</p>
  
  <p>It would be more clear with a extract of my controller and views:</p>
  
  <pre><code>def new
      @post= Post.new
  end
  
  def create
      @post = Post.new(params.require(:post).permit(:title, :category_id))
  
      if params[:previewButt] == "Continue to Preview your Post"
        render :create
      elsif params[:createButt] == "OK! Continue to Post it"
        if @post.save!
        redirect_to root_path
        else
        render :new
        end 
      elsif params[:backButt] == "Make changes"
        render :new
      end
    end
  </code></pre>
  
  <p>My <strong>New</strong> view (extract):</p>
  
  <pre><code>&lt;%= simple_form_for @post do |form| %&gt;
  &lt;%= form.input :title, input_html: { class: 'post-title-input' }, label: false, hint: '"Your post title"' %&gt;
  &lt;%= form.collection_radio_buttons(:category_id, Category.all, :id, :name, :item_wrapper_class =&gt; "selectable" ) %&gt;
  &lt;%= form.button :submit , name: "previewButt", value: "Continue to Preview your Post",  class: "btn btn-lg btn-primary btn-preview" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>My <strong>Create</strong> view (extract):</p>
  
  <pre><code>&lt;%= simple_form_for @post do |form| %&gt;
  &lt;%= form.hidden_field :title, {:value =&gt; @post.title} %&gt;
  &lt;%= form.hidden_field :category_id, {:value =&gt; @post.category_id} %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Note that the problem is not when saving, the model definitions work ok, the problem is only in the simple_form.</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
      belongs_to :category
      validates :title, presence: true
      validates :category_id, presence: true
  end
  </code></pre>
  
  <p><strong>SOLUTION</strong> thanks to the <a href="https://stackoverflow.com/users/1141264/dickieboy">DickieBoy</a> hint:</p>
  
  <p>Change the controller to:</p>
  
  <pre><code>      def create
          @post = Post.new(params.require(:post).permit(:title, :category_id))
  
          if params[:previewButt] == "Continue to Preview your Post"
             if @post.valid? 
                render :create
             else
                render :new 
          elsif params[:createButt] == "OK! Continue to Post it"
            if @post.save!
            redirect_to root_path
            else
            render :new
            end 
          elsif params[:backButt] == "Make changes"
            render :new
          end
        end
  </code></pre>