Update:
Checking the console, a lot of the users are actually going into the database, even when this error message appears!
Even weirder, you will notice that I have a redirect to root_path on a successful save to the database. it never goes there. This is the log. If it saves, it sometimes goes to the show action but there’s actually a moment when the browser appears to get stuck, everything blanks it and I have to click in the address field to push it through to show.index.html.
Redirected to http://localhost:3000root_path
Completed 302 Found in 34ms
[2012-01-08 18:08:27] ERROR URI::InvalidURIError: the scheme http does not accept registry part: localhost:3000root_path (or bad hostname?)
/Users/mel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/generic.rb:746:in `rescue in merge'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/generic.rb:743:in `merge'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in `setup_header'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in `send_response'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:86:in `run'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Original Question:
I’m creating a form for users to sign up to win an ipad. It’s got two fields, email and name.
When I submit the form, I keep getting the same error message no matter what email i enter
1 error prohibited this from being saved:
There were problems with the following fields:
Email has already been taken
Strangely, when I debug params, it shows whatever new email address I enter.
utf8: "\xE2\x9C\x93"
authenticity_token: UgkHFLBfKYM2tZ11u6ItWvPS5XeTIMhFuJDwvhgqe30=
ipad: !map:ActiveSupport::HashWithIndifferentAccess
name: Amy
email: franz@gmail.com
commit: Sign up
action: create
controller: ipads
Anyone have any idea? I’m a bit of a noob…
I’m just adding this code to an Enki blog I’m making on Rails…
I have this validation on my ipad.rb model (note, I had a column for a Twitter address in the migration that I’m just ignoring in the form)
attr_accessible :name, :email, :twitter
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:uniqueness => true
This is my ipads_controller.rb
class IpadsController < ApplicationController
def new
@ipad = Ipad.new
@title = "iPad Contest"
end
def create
@ipad = Ipad.new(params[:ipad])
if @ipad.save
redirect_to 'root_path'
else
@title = "Poo"
render 'new'
end
end
end
This is my new.html.erb
<h1>Win an iPad</h1>
<%= @title %>
<h1>Sign up for iPad</h1>
<%= form_for(@ipad) do |f| %>
<%= render 'shared/errror_messages' %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= debug params %>
Using redirect_to root_path instead of redirect_to ‘root_path’ fixed it. Noob error.