Michael Hartl's ROR Tutorial: CH 7 Sign up form ISSUES!!!

28 views
Skip to first unread message

Colin Stodd

unread,
Apr 11, 2014, 2:37:53 PM4/11/14
to rubyonra...@googlegroups.com
So I've gone over this tutorial, literally recreated the app 4 times but I keep getting stuck at the create user with a form in Ch 7. Rails 3 edition.

From what I can tell, there is no action (Post) being created when I click on the submit button (no user being created, or errors being generated).  It reads it as (GET).  And when I click the button, the URL shows my authenticity-token....... blah blah...(not sure if that can help explain my problem).  Please can someone help me get past this. I have looked for nearly weeks with no avail.

User.rb
```
class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password

  # Downcases all users email's in the database
  before_save { email.downcase! }

  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
            uniqueness: { case_sensitive: false }
 
  # Creates and authenticates a secure password w. password_digest.
  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true


end

```

routes.rb

```
  resources :users

  root to: "static_pages#home"

  match "/signup",  to: "users#new"

  match "/about",   to: "static_pages#about"
  match "/contact", to: "static_pages#contact"


```


new.html.erb:

```
<form class="form">
  <div class="container-fluid">
    <div class="row">
      <div class="col-xs-7 col-md-7">
        <%= 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>
  </div>
</form
>

```

users.controller.rb
```
class UsersController < ApplicationController
    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] = "Welcome personal web application!"
      redirect_to @user
    else
      render 'new'
    end
  end

end


```

Frederick Cheung

unread,
Apr 11, 2014, 4:39:42 PM4/11/14
to rubyonra...@googlegroups.com
On Friday, April 11, 2014 7:37:53 PM UTC+1, Colin Stodd wrote:
> So I've gone over this tutorial, literally recreated the app 4 times but I keep getting stuck at the create user with a form in Ch 7. Rails 3 edition.
>
> From what I can tell, there is no action (Post) being created when I click on the submit button (no user being created, or errors being generated).  It reads it as (GET).  And when I click the button, the URL shows my authenticity-token....... blah blah...(not sure if that can help explain my problem).  Please can someone help me get past this. I have looked for nearly weeks with no avail.
>
> ```
> <form class="form">
>   <div class="container-fluid">
>     <div class="row">
>       <div class="col-xs-7 col-md-7">
>         <%= form_for(@user) do |f| %>


Your error is here - you've got a form within a form which is invalid html

Fred

Colin Stodd

unread,
Apr 11, 2014, 6:01:29 PM4/11/14
to rubyonra...@googlegroups.com
I wish I could buy you a drink of your choice Frederick.  Thank you for taking the time to look over my post!  It's truly appreciated! 
Reply all
Reply to author
Forward
0 new messages