Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails form_for submit button not working

Thank you for your patience. Still pretty new to Rails.

Using Rails 3.2

Making a signup page for a simple app. My problem is that the submit button on my form doesn't cause any effect, whether the information in the form is valid or not.

The User model and database both seem to work fine. If I add a user manually from the rails console, it will add it to the database. As far as I can tell, the issue seems to be in the form generated by form_for.

Here is the page in question:

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
    <div class="span6 offset3>
        <%= form_for(@user) do |f| %>
            <%= render 'shared/error_messages' %>

            <%= f.label :name %>
            <%= f.text_field :name %>

            <%= f.label :email %>
            <%= f.text_field :email %>

            <%= f.label :password %>
            <%= f.password_field :password %>

            <%= f.label :password_confirmation, "Confirmation" %>
            <%= f.password_field :password_confirmation %>

            <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
        <% end %>
    </div>
</div>

And here is my users controller:

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
        if @user.save
            flash[:success] = "Thank you for signing up! Please check your email to confirm your account."
            redirect_to @user
        else
            render 'new'
        end
    end
end

Submit doesn't cause any type of error - simply doesn't cause anything to happen at all. So no valuable information in the logs.

Thank you in advance for any insight.

EDIT: Adding code from /shared/_error_messages.html.erb partial

<% if @user.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-error">
      The form contains <%= pluralize(@user.errors.count, "error") %>.
    </div>
    <ul>
    <% @user.errors.full_messages.each do |msg| %>
      <li>* <%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>
like image 665
jmknoll Avatar asked Dec 20 '22 16:12

jmknoll


1 Answers

Well there's a nice little lesson in careful coding:

<div class="row">
    <div class="span6 offset3>
        <%= form_for(@user) do |f| %>

should have been:

<div class="row">
    <div class="span6 offset3**"**>
        <%= form_for(@user) do |f| %>

Quite a difference a closing tag can make.

like image 64
jmknoll Avatar answered Dec 24 '22 01:12

jmknoll