我需要使用docker-compose创建Rails和Mysql容器.当我尝试在容器之间创建链接时docker-compose up
,我得到了
无法启动容器9b271c58cf6aecaf017dadaf5b无法链接到非运行容器:/ puma_db_1 AS/puma_web_1/db
档
Dockerfile
FROM ubuntu:14.04
RUN apt-get -y update
RUN apt-get -y install git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
RUN apt-get -y install libmysqlclient-dev
RUN git clone https://github.com/sstephenson/rbenv.git /root/.rbenv
RUN git clone https://github.com/sstephenson/ruby-build.git /root/.rbenv/plugins/ruby-build
RUN echo 'eval "$(rbenv init -)"' >> $HOME/.profile
RUN echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc
RUN rbenv install 2.1.5
RUN rbenv global 2.1.5
RUN gem install rails -v 4.0.11
ADD app.tar.gz …
Run Code Online (Sandbox Code Playgroud) 我在Ubuntu服务器14.04 AWS实例中遇到了Rails 4.1.7,Phusion Passenger版本4.0.53,nginx/1.6.2的问题,但是使用rails服务器运行良好.
error.log中
App 2029 stdout:App 2029 stderr:sh:1:App 2029 stderr:env:not found App 2029 stderr:App 2029 stdout:[2014-11-12 16:12:26.1580 1979/7feff83f9700 Pool2/Implementation.cpp:287] :无法为application/home/ubuntu/apps/doger生成进程:启动预加载器时出错.错误ID:b7381860错误详细信息保存到:/tmp/passenger-error-SUjzpL.html来自应用程序的消息:找不到JavaScript运行时.有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs.(ExecJS :: RuntimeUnavailable)
/var/lib/gems/1.9.1/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in ' /var/lib/gems/1.9.1/gems/ execjs-2.2.2/LIB/execjs.rb:4:在需要'/var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in 需要' 的/ var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:在 每个' /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/中bundler/runtime.rb:72:在 每个' /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:in require'/ home/ubuntu/apps/doger /配置/ application.rb中:7:在需要' /home/ubuntu/apps/doger/config/environment.rb:2:in 需要' config.ru:3:in instance_eval的" /usr/lib中/红宝石/ vendor_ruby /rack/builder.rb:55:in 新的'config.ru:1:in EVAL' /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in ' 在/ usr /共享/乘客/帮手-scripts/rack-preloader.rb:29:in 'autodetect'
/var/lib/gems/1.9.1/gems/execjs-2.2.2/lib/execjs.rb:5:in<top (required)>'
/var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in<top (required)>'
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:inblock (2 levels) in require'
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:72:inblock in require'
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:inrequire'
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler.rb:133:in<top (required)>' /home/ubuntu/apps/doger/config/environment.rb:2:in
<top …
我有两个容器.第一个容器有独角兽,第二个容器有mongod.
Name Command State Ports
-------------------------------------------------------------------------------------
app_mongodb_1 /entrypoint.sh mongod Up 0.0.0.0:27017->27017/tcp
app_web_1 foreman start Up 0.0.0.0:3000->3000/tcp
Run Code Online (Sandbox Code Playgroud)
当我尝试访问我的rails应用程序返回错误not connect to a primary node for replica set #<Moped::Cluster:69840575665060 @seeds=[<Moped::Node resolved_address="127.0.0.1:27017">]>
,但当我输入docker-compose web run rails c
我可以保存文档:f = Feature.new(name: "test", value: 10) => #<Feature _id: 565deac0616e642856000000, name: "test", value: 10, created_at: nil, updated_at: nil> => f.save => true
配置/ mongodb.yml
development:
sessions:
default:
database: app_development
hosts:
- mongodb
options:
options:
test:
sessions:
default:
database: app_test
hosts:
- mongodb
options:
read: …
Run Code Online (Sandbox Code Playgroud) 我如何使用外键执行或生成迁移?我有municipios
表,我想与表关联ciudades
,表将有这些字段:( nombre_id
名称ID),nombre
(名称),departamento
(部门)在这种情况下如何运行脚手架脚本来生成外键迁移?
我需要分开where
以使用条件验证示例的值
email := "test@test.com"
if email != "" {
db.Where("users.email LIKE ?", "%"+email+"%")
}
db.Where("users.name like ?", "%"+jhon+"%").Find(&users)
Run Code Online (Sandbox Code Playgroud)
返回两个查询:
1: SELECT "users".* FROM "users" WHERE users.email LIKE '%test@test.com%'
2: SELECT "users".* FROM "users" WHERE users.name LIKE '%jhon%'
但我只需要一个查询结果:
SELECT "users".* FROM "users" WHERE users.email LIKE '%test@test.com%' and users.name LIKE '%jhon%'
Run Code Online (Sandbox Code Playgroud)
谢谢!
给出以下形式:
<%= form_for(@ciudad) do |f| %>
<% if @ciudad.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@ciudad.errors.count, "error") %> prohibited this ciudad from being saved:</h2>
<ul>
<% @ciudad.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :nombre %><br />
<%= f.text_field :nombre %>
</div>
<div class="field">
<%= f.label :departamento_id %><br />
<%= f.select :departamento_id , :prompt => "Seleccione el municipio" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
如何deparamento_id …
我在 Rails 中创建了一个应用程序,我想创建一个 puccuentas 模型:
rails g scaffold puccuenta numero:integer pucgrupo_id:integer nombre:string
Run Code Online (Sandbox Code Playgroud)
输出控制台是:
invoke active_record
create db/migrate/20110819163754_create_puccuentas.rb
create app/models/puccuenta.rb
invoke test_unit
create test/unit/puccuenta_test.rb
create test/fixtures/puccuentas.yml
route resources :puccuentas
invoke scaffold_controller
create app/controllers/puccuentas_controller.rb
invoke erb
create app/views/puccuentas
create app/views/puccuentas/index.html.erb
create app/views/puccuentas/edit.html.erb
create app/views/puccuentas/show.html.erb
create app/views/puccuentas/new.html.erb
create app/views/puccuentas/_form.html.erb
invoke test_unit
create test/functional/puccuentas_controller_test.rb
invoke helper
create app/helpers/puccuentas_helper.rb
invoke test_unit
create test/unit/helpers/puccuentas_helper_test.rb
Run Code Online (Sandbox Code Playgroud)
我的文件 inflection.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /puccuenta$/i, '\1puccuentas'
inflect.singular /puccuentas/i, '\1puccuenta'
end
when entering the url http://localhost:3000/puccuentas
ActiveRecord::StatementInvalid in PuccuentasController#index
Mysql2::Error: Table …
Run Code Online (Sandbox Code Playgroud)