【问题标题】:Rails 6 data aren't showing up on heroku local and on applicationRails 6 数据未显示在 heroku 本地和应用程序上
【发布时间】:2020-12-31 00:15:05
【问题描述】:

我正在尝试在 Heroku 上部署 Rails 后端并响应前端应用程序。前端工作正常,但数据未显示在 Heroku 网站和 heroku local 上。它在本地主机上完美运行。

这里是网址:https://smile.herokuapp.com/

我正在使用两种不同的 API,其中之一是 Stripe API。

将应用部署到 Heroku 后,我迁移了数据库

heroku run rake db:migrate
heroku run rake db:seed

再一次,应用程序在本地工作,但在 Heroku 上,数据库丢失了。

提前致谢!

【问题讨论】:

  • 你使用什么数据库?
  • postgreSQL @7urkm3n

标签: ruby-on-rails reactjs postgresql heroku deployment


【解决方案1】:

您的网址有问题,请阅读这两个One | Two

检查CharityIndex.js第21行fetch('http://localhost:3001/charities')

应该是/charities,可以用curl测试一下:

curl -i -H "Accept: application/json" 'https://smile.herokuapp.com/charities'

试试下面的示例:

  componentDidMount(){
    fetch(`/charities`)
    .then(res => res.json())
    .then(charityData => {
        // debugger
        console.log(charityData);
        this.setState({
          charity: charityData
        })
    }
  )

【讨论】:

  • 谢谢!!!数据现在已经存在,但描述和图像仍然不存在。有什么建议吗? @7urkm3n
  • @Sam 确保有关 url,我相信您又遇到了同样的问题。要调试,请检查生产环境中的控制台并在周围玩耍,您会发现 [将提高您的调试技能]))
猜你喜欢
  • 1970-01-01
  • 2020-12-25
  • 2015-08-05
  • 2016-01-14
  • 1970-01-01
  • 2013-05-25
  • 1970-01-01
  • 1970-01-01
  • 2012-11-02
相关资源
最近更新 更多