Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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 gravatar_无方法错误Hartl rails第7章_Ruby_Erb_Nomethoderror_Gravatar_Ruby On Rails 5 - Fatal编程技术网

Ruby gravatar_无方法错误Hartl rails第7章

Ruby gravatar_无方法错误Hartl rails第7章,ruby,erb,nomethoderror,gravatar,ruby-on-rails-5,Ruby,Erb,Nomethoderror,Gravatar,Ruby On Rails 5,在我给gravatar_下定义并打电话之前,一切都很顺利user.email.downcase为零类。下面是我的工作内容。如果您需要任何其他信息,请告诉我 我在url上运行localhost时看到http://localhost:3000/users/1 NoMethodError在用户中#显示 `Showing /Users/nathandewaele/Desktop/workspce/static_pages/app/views/users/show.html.erb where line

在我给gravatar_下定义并打电话之前,一切都很顺利
user.email.downcase
为零类。下面是我的工作内容。如果您需要任何其他信息,请告诉我

我在url
上运行localhost时看到http://localhost:3000/users/1
NoMethodError在用户中#显示

`Showing /Users/nathandewaele/Desktop/workspce/static_pages/app/views/users/show.html.erb where line #6 raised:

undefined method `downcase' for nil:NilClass`
5号线附近的提取源
gravatar\u id=Digest::MD5::hexdigest(user.email.downcase)

app/helpers/users\u helper.rb app/controllers/users\u controller.rb app/controllers/config/routes.rb app/views/users/show.html.erb
``erb

我遇到了同样的问题,很难追踪!如上所述,没有向数据库发送电子邮件。在我更改了model/users.rb文件中的代码后,我的问题似乎自行解决了,这让我感到困惑:
保存之前{self.email=email.downcase}

在我使用
之前保存{self.email=email.downcase!}
。验证位于Rails教程的第6章。不知怎的,我把
电子邮件搞糊涂了。情况不妙
!使用
self.email=email.downcase


这仍然留下了一个谜团,那就是为什么创建帐户时没有电子邮件,而不是一个阻止我继续的错误…

我遇到了同样的问题,很难追踪!如上所述,没有向数据库发送电子邮件。在我更改了model/users.rb文件中的代码后,我的问题似乎自行解决了,这让我感到困惑:
保存之前{self.email=email.downcase}

在我使用
之前保存{self.email=email.downcase!}
。验证位于Rails教程的第6章。不知怎的,我把
电子邮件搞糊涂了。情况不妙
!使用
self.email=email.downcase


这仍然留下了一个谜团,为什么创建帐户时没有电子邮件,而不是阻止我继续的错误…

有相同的问题,在我用代码更新/app/helpers/users\u helper时解决了:

  # Returns the Gravatar for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end

(如清单7.9所示)

也有同样的问题,在我用代码更新/app/helpers/users\u helper时得到了解决:

  # Returns the Gravatar for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end

(如清单7.9所示)

请检查
gravatar_中的用户对象,查看是否有
方法似乎不存在电子邮件,这就是downcase抛出错误的原因。当
user.email.downcase
引发
未定义方法
downcase for nil`错误时,明显返回
nil
。数据库中的用户没有电子邮件。修好它,错误就会消失。斯皮克曼-你说得对!但我只是去实例化一个新用户,电子邮件显示为零
=>#
为什么我的电子邮件在我放入时是零?请检查
gravatar\u中的用户对象是否有
方法似乎不存在电子邮件,这就是downcase抛出错误的原因。当
user.email.downcase
引发一个
未定义方法
downcase for nil`错误,而不是
user.email
显然返回
nil
。数据库中的用户没有电子邮件。修好它,错误就会消失。斯皮克曼-你说得对!但我只是去实例化一个新用户,电子邮件显示为零<代码>=>#
为什么我的电子邮件在我输入时以零的形式输入?这太有用了。谢谢这太有用了。谢谢
```ruby

class UsersController < ApplicationController

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

  def new
        @user = User.new
  end
end
```
```ruby

ActiveRecord::Schema.define(version: 20171108202327) do

  create_table "users", force: :cascade do |t|
    t.string "name"
    t.string "email"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "password_digest"
    t.index ["email"], name: "index_users_on_email", unique: true
  end

end
```
```ruby

Rails.application.routes.draw do

  # get '/new', to: 'users#new'
    get '/show', to: 'users#show'
    get  '/help', to: 'static_pages#help'
    get '/about', to: 'static_pages#about'
    get '/contact', to: 'static_pages#contact'
    get  '/signup',  to: 'users#new'

    resources :users
end
```
```erb

<% provide(:title, @user.name) %>
<div class="row">
  <aside class="col-md-4">
    <section class="user_info">
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
    </section>
  </aside>
</div>
```
  # Returns the Gravatar for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end