Search code examples
ruby-on-railsmaterialize

Submit form is not working


I'm trying to build a submit form for my user_info, but I don't know why this action is not working. Any ideas ?

view :

<div class="modal" id="modal_userinfo">
  <div class="modal-header">
    <h4>Profil :</h4>
  </div>
  <div class="modal-content">
    <%= simple_form_for(Userinfo.new)  do |f| %>
        <div class="row">
          <div class="input-field col s6">
            <%= f.text_field :name, class: "validate" %>
            <label for="last_name">Nom</label>
          </div>
          <div class="input-field col s6">
            <%= f.text_field :surname, class: "validate" %>
            <label for="last_name">Prénom</label>
          </div>
          <div class="input-field col s6">
            <i class="material-icons prefix">account_circle</i>
            <%= f.text_field :pseudo, class: "validate" %>
            <label for="icon_prefix">Pseudo</label>
          </div>
          <div class="input-field col s6">
            <i class="material-icons prefix">phone</i>
            <%= f.text_field :phone, class: "validate" %>
            <label for="icon_telephone">Telephone</label>
          </div>
        </div>
      </div>
    <div class="modal-footer">
      <%= f.button :submit, "Suivant", class: "modal-action waves-effect btn-flat" %>
    </div>
  <% end %>
</div>

And my controller :

def create
  @userinfo = Userinfo.new(userinfo_params)
  @userinfo.user = current_user
  respond_to do |format|
    if @userinfo.save
      format.html { redirect_to @userinfo, notice: 'Userinfo was successfully created.' }
      format.json { render :show, status: :created, location: @userinfo }
    else
      format.html { render :new }
      format.json { render json: @userinfo.errors, status: :unprocessable_entity }
    end
  end
end

private

def userinfo_params
  params.require(:userinfo).permit(:name, :surname, :pseudo, :phone)
end

I don't understand what is wrong into it. I also have some classic routes (ressources userinfo).


Solution

  • The problem is coming from your class on the submit btn. I d'on't know why I had the same problem with Materialize.

    So you have to remove the class like this :

    <%= f.button :submit, "Suivant" %>
    

    And it should work !