我正在使用 parseresource gem,它说我需要创建一个模型。
创建模型:
class Post < ParseResource
fields :title, :author, :body
validates_presence_of :title
end
Run Code Online (Sandbox Code Playgroud)
我只知道如何生成一个模式,它总是继承 ActiveRecord::Base。我应该在命令行中输入什么来创建这个模型?
我正在制作一个宝石来包装 API。该服务需要一些登录参数,因此我创建了一个 Connection 类,通过传入所有登录值并与实例变量一起存储来进行初始化。@secret_access_key显然,这些价值之一是秘密的。它在应用程序中不可读。但是在 irb 中测试 gem 时,我看到在返回对象时与所有其他实例变量一起显示的密钥。
mws = MWS::Connection.new :access_key => '1', :secret_access_key => 'SECRET!!!', :merchant_id => '3', :marketplace_id => '4'
=> #<MWS::Connection:0x007fbd22acef40 @access_key="1", @merchant_id="3", @marketplace_id="4", @secret_access_key="SECRET!!!">
Run Code Online (Sandbox Code Playgroud)
我很担心密钥会出现在 Heroku 日志、应用程序错误消息或其他任何内容中。
我应该担心吗?如果是这样,存储或隐藏此信息的最佳方法是什么?
另外,我正在使用 httparty gem 来管理这个,我可以用那个 gem 做些什么更好的事情?
我正在做一个需要使用另一个 gem 的项目。我想制作这个 gem,但是我知道当一个 gem 被创建时,它可以与 RubyGems 同步并公开,这是我不想要的。我也知道可以使用 Gem In A Box 等实用程序设置私人服务器,但如果可以的话,我也想避免这样做。有没有办法简单地设置一个 gem 而不与 RubyGems 同步?
我在以下位置找到了我的 JDK /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk
我的 .bash_profile 中有这个
export JAVA_HOME=/Library/Java
export PATH=$JAVA_HOME/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
我已经保存了我的更改 source .bash_profile
现在当我尝试跑步时 sudo apt get install gcc
我收到这个错误
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/apt" (-1)
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
我正在尝试容器化 Rails 项目。出于某种原因,我想要一个 Rails 项目,我可以将它复制并粘贴到另一台机器上,这样我就可以在另一台机器上运行它,而不必在另一台机器上运行“捆绑安装”。有没有办法在项目文件夹中安装所有依赖项,将项目文件夹部署到其他机器并直接从那里运行?
我是Rails编程的新手.当我尝试在rails命令提示符下运行命令'bundle install'时,会出现以下错误.
C:\Sites\blog>bundle install
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/.Retrying dependency api due to
error (2/3): Zlib::BufError buffer error
.........
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.1
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.1.8
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.8
Using rack 1.5.2
Using rack-test 0.6.3
Using actionpack 4.1.8
Using mime-types 2.4.3
Using mail 2.6.3
Using actionmailer 4.1.8
Using activemodel 4.1.8
Using arel …Run Code Online (Sandbox Code Playgroud) 我收到此错误:欢迎中的ExecJS :: ProgramError#WelcomeExecJS :: Welcome#index中的ProgramError.
根据其他发布的帖子,因为在Windows上运行的coffee-script-source 1.9.0/1存在问题所以我必须使用命令行降级gem:gem'coffee-script-source','1.8.0 ".当我尝试这样做时,我得到这个错误:
错误:执行gem时...(Gem :: CommandLineError)未知命令coffee-script-source,
我做错了什么?
我正在使用主动管理宝石.
我有与user_id有关系的问题表,当我想添加选择元素显示大量用户的新问题时,有一种方法可以将此选择元素与用户名的搜索输入一起使用吗?
ActiveAdmin.register Question do
permit_params :difficulty, :title, :user
form do |f|
actions
inputs 'Question Details' do
input :user, :as => :select, :collection => User.all
input :difficulty, as: :select, collection: [1,2,3,4]
input :title
end
actions
end
end
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序错误,所以检查heroku rails console:
(master)$ heroku run rails console
Running rails console on morning-river-1349... up, run.8048
/app/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'spring' (= 1.1.3) among 58 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/app/vendor/bundle/ruby/2.2.0:/app/vendor/ruby-2.2.3/lib/ruby/gems/2.2.0', execute `gem env` for more information
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /app/bin/spring:12:in `<top (required)>'
from /app/bin/rails:4:in `load'
from /app/bin/rails:4:in `<main>'
Run Code Online (Sandbox Code Playgroud)
解决方案:我必须将spring开发部分移动到gemfile中的main.
现在该应用程序运行良好但是,有关如何防止heroku跳过开发类别宝石的任何想法?
编辑:抱歉不必要的麻烦,我读了rails 4.1的发布说明{从那时起spring被预加载},因此包含在gemfile中导致了不必要的问题,只是完全删除了它.
我将在我的rails应用程序中使用Debian测试(拉伸)上的bundle install安装一些gem.我收到此错误:
Installing bcrypt 3.1.10 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /tmp/bundler20151208-29851-hg3bi3bcrypt-3.1.10/gems/bcrypt-3.1.10 for inspection.
Results logged to /tmp/bundler20151208-29851-hg3bi3bcrypt-3.1.10/extensions/x86_64-linux/2.1.0/bcrypt-3.1.10/gem_make.out
An error occurred while installing bcrypt (3.1.10), and Bundler cannot continue.
Make sure that `gem install bcrypt -v '3.1.10'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)
但我已经安装bcrypt和bcrypt-ruby使用gem install.