Rails 5.1错误在显示p时从db检索用户(作为联系人)

时间:2017-10-09 23:11:47

标签: ruby-on-rails postgresql centos7

我已经设置了一个Rails 5 / bootstrap主题,该主题设置为root' creatives #index'在routes.rb中,使用广告素材主题(Start Bootstrap.com,使用前端生成器gem)和app / views / creatives文件夹中的文件作为index.html.erb呈现所有部分的部分内容。一切都很好,我为新用户生成了一个联系模型,用于登录/注册/发送表单等。在我添加密码和电子邮件验证后,这个测试也很好(使用db迁移),所有检查都很好。

但是,当我尝试访问联系人显示页面(位于app / views / contacts文件夹中,广告素材旁边(设置了根目录)时,导航到以下内容时显示错误:3000 / contacts / 1这是添加到联系人db的唯一联系人。记录绝对是id = 1。

错误低于

Started GET "/contacts/1" for 127.0.0.1 at 2017-10-09 23:37:02 +0100
Processing by ContactsController#show as HTML
  Parameters: {"id"=>"1"}
  Contact Load (0.8ms)  SELECT  "contacts".* FROM "contacts" WHERE "contacts"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
Return value is: nil

So it returns a value of nil although there is only 1 row in db with the correct id. It seems to be taking the correct params from contacts_controller.rb which is below

def show
    @contact = Contact.find(params[:id])
    debugger
  end
  def new
  end

So I cant figure out whether its a routing problem (contacts is not linked to creatives ?) or there is a db error somewhere (its postgresql)

The routes.rb is below

Rails.application.routes.draw do
resources :contacts
root 'creatives#index'
end

小贴士欢迎!感谢

0 个答案:

没有答案