如何更改ActiveRecord ID的(默认)类型?int不够长,我宁愿长.令我感到惊讶的是,没有:迁移很久 - 是否只使用一些小数?
我试图通过合并来干扰控制器respond_with
.当我这样做时,遵循Railscast中的一些指示,我得到的东西大部分都在工作.问题在于删除资源后的重定向...应该重定向到people_url
...而是尝试加载特定资源.
我找到的示例代码看起来像这样......但是它尝试加载刚删除的资源失败了:
# app/controllers/people_controller.rb
class PeopleController < ApplicationController
respond_to :html, :xml
def destroy
@person = Person.find(params[:id])
flash[:notice] = 'Successfully deleted person.' if @person.destroy
respond_with(@person) # <== spec fails here
end
end
Run Code Online (Sandbox Code Playgroud)
改变最后一行respond_with(@people)
也不起作用(虽然我曾希望它会...)
经过深入挖掘并尽力了解事情,我确实让事情发生了(至少看起来如此.规格传递.app功能)用这个:
respond_with(@person, :location => people_url) # <== now it works
Run Code Online (Sandbox Code Playgroud)
那么,这是处理这个问题的正确方法吗?似乎有了所有'魔法'背后的response_with它会知道删除后它不能重定向到自己?我也认为这个(7种基本的RESTful CRUD方法之一)将是非常基本和基本的,所以很多例子会比比皆是......但我找不到很多,除了那些暗示代码不起作用的代码我.
希望有人可以帮助我理解这里发生的铁轨'魔力'所以当我在路上爆炸时,我不会感到惊讶.
我有Activemessaging插件和rails3应用程序的问题.
我的gemfile是
gem 'sqlite3'
gem 'activemessaging', :git=>'git://github.com/spraints/activemessaging.git'
gem 'stomp'
gem 'daemons'
Run Code Online (Sandbox Code Playgroud)
之后,activemessaging文件夹出现在供应商中
捆绑安装后,我想用生成器创建处理器
rails generate processor Test
Run Code Online (Sandbox Code Playgroud)
我看到这个输出:
ActiveMessaging: adapter reliable_msg not loaded: no such file to load -- reliable-msg
ActiveMessaging: adapter wmq not loaded: no such file to load -- wmq/wmq
ActiveMessaging: adapter beanstalk not loaded: no such file to load -- beanstalk-client
ActiveMessaging: no '/home/ruby/myapp/script/config/messaging.rb' file to load
ActiveMessaging: Loading script/app/processors/application.rb
Rails available: Adding dispatcher prepare callback.
ActiveMessaging: no '/home/ruby/myapp/script/config/messaging.rb' file to load
Could not find generator processor. …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ActiveRecord find_or_create_by_*column*
,但是我从Postgres得到错误让我知道它偶尔找不到模型,并试图插入一个.我保持这个表的独特性非常重要,所以我:unique => true
为它的迁移添加了一个属性,以便Postgres知道我对此非常认真.
并且,失败:
ActiveRecord::StatementInvalid: PGError: ERROR: duplicate key value violates unique constraint "index_marketo_leads_on_person_id" DETAIL: Key (person_id)=(9968932) already exists. : INSERT INTO "marketo_leads" ("mkt_person_id", "synced_at", "person_updated_at", "person_id") VALUES(NULL, NULL, '2011-05-06 12:57:02.447018', 9968932) RETURNING "id"
我有这样的模型:
class User < AR::Base
has_one :marketo_lead
before_save :update_marketo_lead
def update_marketo_lead
if marketo_lead
if (User.marketo_columns & self.changes.keys).any?
marketo_lead.touch(:person_updated_at)
end
elsif self.id
marketo_lead = MarketoLead.find_or_create_by_person_id(:person_updated_at => Time.now, :person_id => self.id)
end
end
end
class MarketoLead
belongs_to :user, :foreign_key => 'person_id'
end
Run Code Online (Sandbox Code Playgroud)
第二个模型用于将我们的用户帐户链接到Marketo电子邮件服务器,并保留上次更改用户的某些字段的记录,以便我们可以在批量后台任务中推送更改的记录.
update_marketo_lead …
我用
rails g scaffold_controller admin/sub/Product name:string
Run Code Online (Sandbox Code Playgroud)
生成crud页面,
现在我需要写route.rb文件来映射admin_sub_product_controller,如何在rails3上写这个路由文件?
我很难编写2级命名空间映射路由
namespace admin do
resource :products
end
Run Code Online (Sandbox Code Playgroud)
这只是/ admin/products的wokrs,但是对于映射admin/sub/proudcts怎么写?
Rails提供filter_parameter_logging来过滤rails日志中的敏感参数.
如果您有一个JSONP API,URL中可能会出现一些敏感信息.有没有办法从日志中过滤请求URL?
activerecord ×2
bigint ×1
callback ×1
filter ×1
int ×1
json ×1
long-integer ×1
respond-with ×1