我正在寻找Ruby on Rails的上传解决方案,我可以同时上传多个大型图像文件,并向上传者显示进度,以便他们知道文件正在上传.我偶然发现了Plupload,这对于我正在尝试做的事情来说似乎很完美,但是我找不到任何关于如何合并到我的应用程序中的Ruby on Rails示例.任何领导,基本示例,甚至更好的Rails文档的替代方法将不胜感激.
谢谢你看:)
目前在我的spec/decorators/product_decorator_spec.rb中,我有以下内容:
require 'spec_helper'
describe ProductDecorator do
let(:product) { FactoryGirl.create(:product) }
subject do
ProductDecorator.first
end
before do
product
end
it 'should render the name attribute with a link to the product page' do
subject.name.should == h.link_to(product.name, 'test')
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行我的规范时,我得到以下内容:
F.....
Failures:
1) ProductDecorator should render the name attribute with a link to the product page
Failure/Error: subject.name.should == h.link_to(product.name, 'resr')
NameError:
undefined local variable or method `h' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fbbf212c8b0>
# ./spec/decorators/product_decorator_spec.rb:15:in `block (2 levels) in <top (required)>'
Finished in 0.98531 …Run Code Online (Sandbox Code Playgroud) 在Rails中,我正在寻找一种方法来为内部记录生成一个自动递增的序列号,以保留模型的新实例.我想避免创建特定于数据库的代码,而是提供一个无论数据库如何都可以工作的解决方案.我目前的想法是等到模型被保存,然后获取已保存模型的ID并将其用作序列号的后缀,但是我必须在创建时保存每个记录两次.
有任何想法吗?
谢谢你的期待!
我正在使用Action Mailer并在我的environment.rb文件中为Action Mailer配置了我的配置.我想将我的项目与environment.rb文件一起发布到公共存储库中,但我不想包含我的邮件服务器的登录信息.如何配置Capistrano的deploy.rb,以便提示用户输入邮件服务器设置,然后在Capistrano部署期间修改或创建environment.rb文件.
谢谢你看=)
在Rails 3.1中,我知道您可以检查是否可以更改模型对象的给定实例,但是如何检查模型的has_many关联的任何实例是否已更改.
例如,假设我有一个包含许多LineItem的Order.LineItems被添加到Order中,我希望能够检查Order的LineItems是否有任何变化.我想一种方法是循环遍历Order模型中的每个LineItem,如下所示:
def line_items_changed?
self.line_items.each do |item|
if item.changed?
return true
else
return false
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是如果有内置或更有效的方式,我很好奇.
在我的模型中,我有以下设置:
class User < ActiveRecord::Base
has_many :assignments
has_many :roles, :through => :assignments
end
class Role < ActiveRecord::Base
has_many :assignments
has_many :users, :through => :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :user
belongs_to :role
attr_accessible :role_id, :user_id
end
Run Code Online (Sandbox Code Playgroud)
在我的factory.rb文件中,我有:
FactoryGirl.define do
factory :user do
sequence(:username) { |n| "user#{n}" }
email { "#{username}@example.com" }
password 'secret'
password_confirmation 'secret'
factory :admin do
...
end
end
factory :role do
name 'Normal'
value 'normal'
end
factory :assignment do
...
end
end
Run Code Online (Sandbox Code Playgroud)
我正在努力弄清楚我将如何添加一个角色:name =>"admin",:value =>"admin",到"user"块内的"admin"工厂,这样我就可以调用了
create(:admin) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个网站,它将拥有一个用户模型,一个提交模型和一个评级模型.每个提交每个用户可能只有一个评级.我的问题是如何在我的模型中设置它?