在尝试"git push heroku master"时,我不断收到错误消息:
Counting objects: 266, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (239/239), done.
Writing objects: 100% (266/266), 222.68 KiB, done.
Total 266 (delta 55), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Gemfile detected, running Bundler version 1.0.3
Unresolved dependencies detected; Installing...
Using --without development:test
You have modified your Gemfile in development but did not check …Run Code Online (Sandbox Code Playgroud) 我有这张桌子:
class CreateShoes < ActiveRecord::Migration
def change
create_table :shoes do |t|
t.string :name
t.boolean :leather
t.integer :season
t.timestamps null: false
end
end
end
Run Code Online (Sandbox Code Playgroud)
'season'专栏应该叫'season_id'.我知道我必须写't.rename:season,:season_id',如http://edgeguides.rubyonrails.org/active_record_migrations.html#column-modifiers中所述,但我无法找到正确的语法.应该是吗?
class CreateShoes < ActiveRecord::Migration
def change
create_table :shoes do |t|
t.string :name
t.boolean :leather
t.integer :season
t.timestamps null: false
end
change_table :products do |t|
t.rename :season, :season_id
end
end
end
Run Code Online (Sandbox Code Playgroud)
不行.我在Mac控制台中需要做什么?谢谢!
出于某种原因,当使用json或xml向我的应用程序发出请求时,我得到一个InvalidAuthenticityToken.我的理解是rails应该只为html或js请求提供真实性令牌,因此我不应该遇到这个错误.到目前为止,我发现的唯一解决方案是禁用protect_from_forgery来执行我想通过API访问的任何操作,但由于显而易见的原因,这并不理想.思考?
def create
respond_to do |format|
format.html
format.json{
render :json => Object.create(:user => @current_user, :foo => params[:foo], :bar => params[:bar])
}
format.xml{
render :xml => Object.create(:user => @current_user, :foo => params[:foo], :bar => params[:bar])
}
end
end
Run Code Online (Sandbox Code Playgroud)
每当我将请求传递给操作时,这就是我在日志中获得的内容:
Processing FooController#create to json (for 127.0.0.1 at 2009-08-07 11:52:33) [POST]
Parameters: {"foo"=>"1", "api_key"=>"44a895ca30e95a3206f961fcd56011d364dff78e", "bar"=>"202"}
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
thin (1.2.2) lib/thin/connection.rb:76:in `pre_process'
thin (1.2.2) lib/thin/connection.rb:74:in `catch'
thin (1.2.2) lib/thin/connection.rb:74:in `pre_process'
thin (1.2.2) lib/thin/connection.rb:57:in `process'
thin (1.2.2) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.8) lib/eventmachine.rb:242:in `run_machine'
eventmachine (0.12.8) …Run Code Online (Sandbox Code Playgroud) 我只是找不到你可以用一个dyno在heroku上托管多少个应用程序?
我打算主持很多流量很小的小应用程序.
谢谢你的回答
我有一个相对简单的Rails应用程序,我想存储管理员用户在应用程序运行时可以更改的各种配置设置,例如,允许对帖子发表评论或更改日期的显示格式.
我知道我可以在environment.rb文件中存储常量等,但是这些似乎只在服务器重新启动时才加载.
是否有替代的地方我可以定义这些信息,或者将它保存在数据库中会更好吗?
任何建议表示赞赏
谢谢.
我从3.2升级到Rails4.我有以下查询:
progress = Progress.find_or_initialize_by_chore_id_and_period_and_account_id(chore.id, period[chore.frequency], chore.account_id)
Run Code Online (Sandbox Code Playgroud)
在运行测试时,我收到了弃用警告
DEPRECATION WARNING: This dynamic method is deprecated. Please use e.g. Post.find_or_initialize_by(name: 'foo') instead. (called from bump_progress at /Users/newimac/RailsApp/bank/app/models/child.rb:200)
Run Code Online (Sandbox Code Playgroud)
所以,我更新了我的查询如下:
progress = Progress.where('chore.id' => 'chore_id', 'period[chore.frequency]' => 'period', 'chore.account_id' => 'account_id').first_or_initialize
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我的查询是否正确?
我有一个Product模特.
如何在控制器中获取Rails 3中产品的URL.
例如(伪代码):
def foobar
@product = Product.first
puts @product.url
end
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?
最近无法使用Heroku连接控制台:
lsoave@ubuntu:~/rails/github/gitwatcher$ heroku run console
Running console attached to terminal...
Timeout awaiting process
lsoave@ubuntu:~/rails/github/gitwatcher$
Run Code Online (Sandbox Code Playgroud)
它会发生在其他人身上吗?
以下是M Hartl的Ruby on Rails教程中的一些代码.任何人都可以解释为什么实例变量(@user)是必要的,为什么不使用局部变量.此外,由于实例变量应该是类实例中的变量,哪个类是@user实例化的?
require 'spec_helper'
describe User do
before { @user = User.new(name: "Example User", email: "user@example.com") }
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
end
Run Code Online (Sandbox Code Playgroud) 好的,我有
>> list = Request.find_all_by_artist("someBand")
=> [#<Request id: 1, artist: "someBand", song: "someSong", venue: "Knebworth - Stevenage, United Kingdom", showdate: "2011-07-01", amount: nil, user_id: 2, created_at: "2011-01-01 18:14:08", updated_at: "2011-01-01 18:14:09".............
Run Code Online (Sandbox Code Playgroud)
然后
list.group_by(&:created_at).map {|k,v| [k, v.length]}.sort
=> [[Sat, 01 Jan 2011 18:14:08 UTC +00:00, 10], [Sun, 09 Jan 2011 18:34:19 UTC +00:00, 1], [Sun, 09 Jan 2011 18:38:48 UTC +00:00, 1], [Sun, 09 Jan 2011 18:51:10 UTC +00:00, 1], [Sun, 09 Jan 2011 18:52:30 UTC +00:00, 1], [Thu, 10 Feb …Run Code Online (Sandbox Code Playgroud)