Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道:';电子邮件已被接收';对于我输入的每封电子邮件_Ruby On Rails - Fatal编程技术网

Ruby on rails 轨道:';电子邮件已被接收';对于我输入的每封电子邮件

Ruby on rails 轨道:';电子邮件已被接收';对于我输入的每封电子邮件,ruby-on-rails,Ruby On Rails,更新: 检查控制台,许多用户实际上正在进入数据库,即使出现此错误消息 更奇怪的是,在成功保存到数据库时,您会注意到我重定向到root_路径。它从不去那里。这是日志。如果保存,它有时会转到“显示”操作,但实际上有一个时刻,浏览器似乎卡住了,所有内容都将其清空,我必须单击“地址”字段以将其推送到show.index.html Redirected to http://localhost:3000root_path Completed 302 Found in 34ms [2012-01-08 18:

更新: 检查控制台,许多用户实际上正在进入数据库,即使出现此错误消息

更奇怪的是,在成功保存到数据库时,您会注意到我重定向到root_路径。它从不去那里。这是日志。如果保存,它有时会转到“显示”操作,但实际上有一个时刻,浏览器似乎卡住了,所有内容都将其清空,我必须单击“地址”字段以将其推送到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'
原始问题:

我正在创建一个表单,供用户注册以赢得ipad。它有两个字段,email和name。 当我提交表单时,无论我输入什么电子邮件,我都会收到相同的错误消息

1 error prohibited this from being saved:

There were problems with the following fields:

    Email has already been taken
奇怪的是,当我调试params时,它会显示我输入的任何新电子邮件地址

utf8: "\xE2\x9C\x93"
authenticity_token: UgkHFLBfKYM2tZ11u6ItWvPS5XeTIMhFuJDwvhgqe30=
ipad: !map:ActiveSupport::HashWithIndifferentAccess 
  name: Amy
  email: franz@gmail.com
commit: Sign up
action: create
controller: ipads
有人知道吗?我有点傻

我只是将此代码添加到我在Rails上制作的Enki博客中

我在我的ipad.rb模型上进行了验证(注意,我在迁移中有一个Twitter地址栏,我只是在表单中忽略了该栏)

这是我的iPad_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
class IpadsController
这是我的新.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 %> 
赢得一台iPad
注册iPad



使用重定向到根路径而不是重定向到“根路径”修复了此问题。Noob错误

您的模型中是否包含了
:电子邮件
中的attr\u accessible
?是的,我包含了。我将更新OP.attr_accessible:name,:email,:twitter错误消息实际上在用户模型上,而不是iPad模型上
1错误禁止保存此**用户**:
是否可以更新用户模型与iPad模型的关系?@Jessewolgamot谢谢,这是因为我从其他地方复制了代码,忘了更改该部分,尽管我已更改了与错误消息相关的所有其他变量。请将redirect_改为'root_path'改为
redirect_改为root_path
,然后查看是否仍有问题。
<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 %>