小编Ste*_*lar的帖子

未初始化的常量ApplicationRecord

我正在线上的rails教程书,当我转到http:// localhost:3000 /时,我收到以下错误消息

"未初始化的常量ApplicationRecord"

它给了我以下代码突出显示第一行.

class User < ApplicationRecord
  attr_accessor :remember_token
  before_save { self.email = email.downcase }
  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, length: { maximum: 255 },
Run Code Online (Sandbox Code Playgroud)

这是我的application.html.erb文件:

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "application", media: "all",
                                           "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <% …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails localhost railstutorial.org ruby-on-rails-4

12
推荐指数
3
解决办法
1万
查看次数

由于未跟踪的工作树文件将被合并错误覆盖,因此无法继续变基

我目前正在使用 合并两个分支git rebase -i,有一个提交不允许我继续变基。当我检查提交时,我看到有一些文件,但没有与分支冲突。

在此输入图像描述

我尝试使用fixupandedit因为我想也许我做了一些改变,但事实并非如此。当我运行时git rebase --continue,我收到以下消息:

error: The following untracked working tree files would be overwritten by merge:
Run Code Online (Sandbox Code Playgroud)

它还显示如上图所示的文件,并显示以下消息

Please move or remove them before you merge.
Aborting
hint: Could not execute the todo command
hint: 
hint:     pick 430847f3fe3f80162a93f62db3e016f3c9a97cc1 Include html2text package
hint: 
hint: It has been rescheduled; To edit the command before continuing, please
hint: edit the todo list first:
hint: 
hint:     git rebase --edit-todo
hint:     git rebase --continue
Run Code Online (Sandbox Code Playgroud)

这种情况我能做什么?这是否意味着我可以重新调整此提交的基础?我必须堕胎吗?

git

11
推荐指数
1
解决办法
1万
查看次数

未处理的拒绝错误:此合同对象尚未设置地址,请先设置一个地址

我目前正在尝试使用Infura通过Web3在我的机器上运行。设置运行node index.js文件时,出现以下错误:

Unhandled rejection Error: This contract object doesn't have address set yet, please set an address first.
    at Object._processExecuteArguments (/Users/Oso.Lu/cryptokitty-miner/node_modules/web3-eth-contract/src/index.js:739:15)
    at Object._executeMethod (/Users/Oso.Lu/cryptokitty-miner/node_modules/web3-eth-contract/src/index.js:760:54


var helpers = require("./helpers.js")

var Web3 = require('web3');
var Tx = require('ethereumjs-tx');

// You should be running a local Eth node or use Infura.
var web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io:443"));
var prompt = require('prompt');


var sendingAddress = "********************"  // with your sending ETH address
var pKey = "******************************"; // This will store the corresponding …
Run Code Online (Sandbox Code Playgroud)

ethereum web3js

7
推荐指数
1
解决办法
2707
查看次数

#&lt;RSpec :: ExampleGroups :: UserName:&gt;的未定义方法`build'

我目前正在使用Rails 4.2.6RSpec 3.7版本。运行测试时,出现以下错误:

undefined method `build' for #<RSpec::ExampleGroups::UserName:0x007ff984a99d38>
Run Code Online (Sandbox Code Playgroud)

触发此错误的是以下代码。需要'rails_helper'

RSpec.describe User, "name" do
  #setup
  it "returns the email" do
    #build
    user = build(:user, email: "everlastingwardrobe@example.com")
    # excercise and verify
    expect(user.email).to eq "everlastingwardrobe@example.com"
  end
end
Run Code Online (Sandbox Code Playgroud)

我使用build而不是create,因为我不想将数据持久保存到数据库中。但是,我正在使用,factory_bot_rails因此我应该可以使用此方法。

这是我的Gemfile:

group :development, :test do
  gem 'rspec'
  gem 'rspec-rails'
  gem 'factory_bot_rails'
  gem 'byebug'
  gem 'pry'
  gem 'pry-nav'
  gem 'pry-stack_explorer'
end

group :test do
  gem "capybara"
  gem "selenium-webdriver"
end
Run Code Online (Sandbox Code Playgroud)

spec_helper.rb

# This file is copied to spec/ when you run …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails-4 factory-bot

7
推荐指数
1
解决办法
1462
查看次数

委托给附件的变体,但附件为零

我正在使用 ActiveStorage 开发 Rails 6 应用程序。我正在使用 devise 进行身份验证,这需要在 sign_up 页面上提供电子邮件和密码。成功注册后,我想重定向到编辑个人资料。用户不一定需要上传头像或其他一些字段。如果这是用户的选择,这些可以留空。

ActionView::Template::Error (variant delegated to attachment, but attachment is nil):
    3: 
    4: <p><%= @user.full_name %><p>
    5: <p>
    6:   <%= image_tag @user.avatar.variant(resize_to_limit: [100, 100])%>
    7: <p>
    8: <p><%= @user.city %><p>
    9: <p><%= @user.bio %><p>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误,但我希望这些字段是可选的,我该如何实现?用户/edit.html.erb

  <%= form_for @user do |f| %>
    <div class="form-group">
      <%= f.label :avatar %>
      <%= f.file_field :avatar, as: :file, class: "form-control" %>
    </div>

    <div class="form-group">
      <%= f.label :full_name, 'Full Name' %>
      <%= f.text_field :full_name, autofocus: true, class: "form-control" %> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-activestorage

7
推荐指数
1
解决办法
5079
查看次数

Home#index 中的 ActiveStorage::InvariableError

目前我正在尝试在 Rails 6 中显示.HEIC图像。我正在使用ActiveStorage ImageMagic来使用变体来显示jpg. 基本上我正在尝试使用

mogrify -format jpg myimage.heic
Run Code Online (Sandbox Code Playgroud)

在图像中进行显示jpg

我添加Rails.application.config.active_storage.variant_processor到 application.rb 中以便能够使用该变体。然而,它似乎打破了以下行:

 <%= image_tag post.image.variant(format: 'jpg'), class: "card-home__img" %>
Run Code Online (Sandbox Code Playgroud)

为什么不工作?

ruby-on-rails imagemagick rails-activestorage ruby-on-rails-6

7
推荐指数
2
解决办法
6033
查看次数

错误 -- ddtrace: [ddtrace] 无法打开与 localhost:8126 的 TCP 连接(连接被拒绝 - “localhost”端口 8126 的 connect(2))

我目前正在开发一个尚未部署的 Ruby on Rails 项目。在开发环境中工作时,每次运行rails console或服务器时,我都会收到完整的错误消息:

ERROR -- ddtrace: [ddtrace] (/Users/stevenaguilar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ddtrace-0.8.0/lib/ddtrace/transport.rb:73:in `rescue in post') Failed to open TCP connection to localhost:8126 (Connection refused - connect(2) for "localhost" port 8126)
Run Code Online (Sandbox Code Playgroud)

我想我可以通过将配置更改为仅在生产中工作来解决这个问题。 config/initializers/datadog-tracer.rb

Rails.configuration.datadog_trace = {
  auto_instrument: true,
  auto_instrument_redis: true,
  default_service: 'my-rails-app'
}
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails datadog

5
推荐指数
1
解决办法
7796
查看次数

由于 rb-readline,使用 Elastic Beanstalk 将 Rails 5 应用程序部署到 AWS 时出现问题

我正在尝试使用 elastic beanstalk 将代码部署到 AWS,但在部署时不断遇到错误。

我添加了一个 gem 'rb-readline',当我检查日志时,我发现该 gem 在部署中存在错误。我不记得添加 gem 'rb-readline' 修复了什么错误,但我不知道删除 gem 是否可以解决这个问题。这是gem的链接: https: //github.com/ConnorAtherton/rb-readline

这是部署的错误日志。

Application update failed at 2017-10-24T19:27:36Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed.

++ /opt/elasticbeanstalk/bin/get-config container -k script_dir
+ EB_SCRIPT_DIR=/opt/elasticbeanstalk/support/scripts
++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
+ EB_APP_STAGING_DIR=/var/app/ondeck
++ /opt/elasticbeanstalk/bin/get-config container -k app_user
+ EB_APP_USER=webapp
++ /opt/elasticbeanstalk/bin/get-config container -k support_dir
+ EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
+ . /opt/elasticbeanstalk/support/envvars
++ export RACK_ENV=production
++ RACK_ENV=production
++ export RAILS_SKIP_ASSET_COMPILATION=false
++ RAILS_SKIP_ASSET_COMPILATION=false
++ export RAILS_SKIP_MIGRATIONS=false
++ RAILS_SKIP_MIGRATIONS=false
++ export …
Run Code Online (Sandbox Code Playgroud)

ruby amazon-web-services amazon-elastic-beanstalk ruby-on-rails-5

5
推荐指数
1
解决办法
2079
查看次数

Docker:COPY 未能找到 Gemfile:没有这样的文件或目录

我目前正在通过 docker 设置 Rails 样板。当我尝试运行时docker build .,出现以下错误:

Step 5/8 : COPY Gemfile /app/
COPY failed: stat /var/lib/docker/tmp/docker-builder090950451/Gemfile: no such file or directory
Run Code Online (Sandbox Code Playgroud)

我正在按照文档中的说明进行操作,但仍然无法构建图像。

这是我的 Dockerfile

FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

WORKDIR /app

# Copy the existing Gemfile
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock

# Install Gems
RUN bundle install
COPY . /app
Run Code Online (Sandbox Code Playgroud)

我还有以下docker-compose.yml文件:

version: '3'
services:
  db:
    image: postgres # To Edit - Default …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails docker docker-compose

3
推荐指数
1
解决办法
4319
查看次数

无法将 Rails 6 应用程序上的 TailwindCSS 部署到 Heroku

我目前正在尝试将我的 rails 6 应用程序部署到 Heroku。我在一篇关于类似问题的帖子中尝试了答案,但没有运气。. 我不确定错误来自哪里,因为这些样式在开发中运行良好,但在推送到生产时会中断。不确定它是否与当前正在使用 sass 编译 css 资产有关?

 [14] ./node_modules/@rails/actiontext/app/javascript/actiontext/index.js + 1 modules 2.64 KiB {0} [built]
remote:             |    2 modules
remote:            + 7 hidden modules
remote:        
remote:        ERROR in ./app/javascript/stylesheets/application.scss
remote:        Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
remote:        ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
remote:        
remote:        @import "tailwindcss/base";
remote:        ^
remote:              File to import not found or unreadable: tailwindcss/base.
remote:              in /tmp/build_d98149372aae5001d8aada1182784254/app/javascript/stylesheets/application.scss (line 1, column 1)
remote:            at runLoaders (/tmp/build_d98149372aae5001d8aada1182784254/node_modules/webpack/lib/NormalModule.js:316:20)
Run Code Online (Sandbox Code Playgroud)

不知道为什么File to import …

ruby-on-rails heroku tailwind-css ruby-on-rails-6

3
推荐指数
1
解决办法
1589
查看次数