我无法从本地计算机访问我的容器化 Rails 应用程序。我将此快速入门指南作为模板,并对 gemfile 和 gemfile.lock 的路径进行了一些调整。快速入门指南继续介绍 docker-compose,但我想尝试在没有它的情况下访问该应用程序,以便在继续之前熟悉这些流程。
这是我的 dockerfile:
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile ./Gemfile
COPY Gemfile.lock ./Gemfile.lock
RUN gem install bundler -v 2.0.1
RUN bundle install
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000:3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"] …Run Code Online (Sandbox Code Playgroud) 我有一个克隆给我的客户的 ruby gem。
根据此处的文档(https://github.com/Jbur43/usps_counties)
我必须require 'usps_counties'加载它。
所以我的路径是/usps_counties。从那里我加载 irb 并尝试要求 usps_counties 文件,但找不到它。
然后我转到 /usps_counties/lib(该文件位于 lib 目录中),加载 irb 并尝试要求它但找不到它。
我在这里做错了什么?
我正在阅读"使用rails进行敏捷Web开发"一书,我正在进行验证的部分,如下所示:
class Product < ActiveRecord::Base
validates :description, :title, :image_url, presence: true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
validates :image_url, allow_blank: true, format: {
with: %r{\.(gif|jpg|png)\z}i,
message: 'Must include an image file extension'
}
end
Run Code Online (Sandbox Code Playgroud)
我不理解的是我们将image_url,allow_blank设置为true,但是我们必须验证image_url是否存在?乍一看,这似乎与我相矛盾,但我确信这是因为缺乏理解.
allow_blank验证是做什么的?为什么我们不验证:价格也存在?
我在rails应用程序中使用materialize作为UI框架,除了'material-icons''菜单'选项无法正常工作外,一切正常.
完整的代码在下面,但这是不合适的部分:
<a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
Run Code Online (Sandbox Code Playgroud)
当我缩小浏览器以触发响应时,它不会变成汉堡包图标,而只是显示文本节点"菜单".我无法弄清楚我做错了什么.其他一切都在发挥作用.
这是整个导航/下拉结构:
<!-- Dropdown Structure -->
<ul id="dropdown1" class="dropdown-content">
<li><a href="#!">My Profile</a></li>
<li><a href="#!">My Courses</a></li>
<li class="divider"></li>
<li><a href="#!">Logout</a></li>
</ul>
<!-- Dropdown Structure -->
<ul id="dropdown2" class="dropdown-content">
<li><a href="#!">My Profile</a></li>
<li><a href="#!">My Courses</a></li>
<li class="divider"></li>
<li><a href="#!">Logout</a></li>
</ul>
<header>
<nav class="z-depth-2">
<div class="container">
<div class="nav-wrapper">
<a href="#!" class="brand-logo">OppSim</a>
<a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<!-- web view -->
<li><a href="#">Courses</a></li>
<li><a href="#">Signup</a></li>
<li><a href="#">Login</a></li>
<!-- Dropdown Trigger -->
<li><a class="dropdown-button" href="#!" …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个使用实例变量的products_controller.我对Ruby中实例变量的理解是你可以在同一个类的不同方法中使用它们.那么为什么我们在rails应用程序的多种方法中使用相同的实例变量呢?下面我们有一个实例变量@product设置两次,当我们在create动作中使用时,新动作中的@product变量是否被覆盖?
我对同一类方法中这些变量的范围感到有点困惑.
def new
@product = Product.new
end
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render :show, status: :created, location: @product }
else
format.html { render :new }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习 Elixir 和函数编程,但在理解 Elixir in Action 一书中的这个例子时遇到了困难。
defmodule ListHelper do
def sum([]), do: 0
def sum([head | tail]) do
head + sum(tail)
end
end
ListHelper.sum([12,3,4])
Run Code Online (Sandbox Code Playgroud)
这个的返回值是 19,但我不明白的是这些值是如何累积的。
我认为 head 正在不断更新,然后当模式匹配到[]然后累积的 head 将被添加到0并且该函数将退出,但是在使用它之后我现在认为这不是正在发生的事情。有人可以为这个例子中发生的事情提供另一种解释吗?如果我需要解释更多,我可以尝试重新审视这个。
当我启用预览模式时,调试器会在我的站点上弹出,因此跟踪 ID 似乎是正确的。
我的标签配置如下所示:
type: UA, track-type: event, category: next-question, label: {{Click Element}}, non-interaction: true, GA-settings: {{smb tracking-id}}
我的触发器配置如下所示:
trigger-type: click all-elements, this-trigger-fires-on: some-clicks, fire-trigger-when: Click Classes...Contains...next-question
我的另一个事件是一个通用的页面点击事件。
它们都在预览模式下触发,但它不会显示在 /behavior/events 下的 Google Analytics 中。
非常感谢对此的任何想法/见解。