Tag: ruby on rails

使用Paperclip和AWS上传大文件时出错

Heroku上的我的rails应用程序允许用户使用回形针上传照片以存储在amazon web servicesS3上。 当照片的大小超过1.5MB时,应用程序似乎超时了。 解决这个问题的最佳方法是什么? 如果有帮助,这是堆栈跟踪? E, [2013-10-07T14:15:57.018396 #5] ERROR — : /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call’ 2013-10-07T14:15:57.018974+00:00 app[web.2]: E, [2013-10-07T14:15:57.018430 #5] ERROR — : /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward’ 2013-10-07T14:15:57.018974+00:00 app[web.2]: E, [2013-10-07T14:15:57.018772 #5] ERROR — : /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass’ 2013-10-07T14:15:57.018974+00:00 app[web.2]: E, [2013-10-07T14:15:57.018946 #5] ERROR — : /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!’ 2013-10-07T14:15:57.019152+00:00 app[web.2]: E, [2013-10-07T14:15:57.018983 #5] ERROR — : /app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call’ 2013-10-07T14:15:57.019152+00:00 […]

Rails简单模型属性未保存到数据库

我正在开发一个小型Rails 3应用程序,用于从Steam API读取数据。 我所看到的是我创建的任何ActiveRecord模型的模型属性都没有保存到数据库中,如果我debug它们也不输出。 这是我的样本模型 class NonPlayableApp < ActiveRecord::Base attr_accessor :name, :steam_id attr_accessible :name, :steam_id end 迁移文件为: class CreateNonPlayableApps < ActiveRecord::Migration def change create_table :non_playable_apps do |t| t.string :name t.string :steam_id t.timestamps end end end 以下是使用Rails控制台进行的一些测试,当我在控制器中尝试它们并inspect或模拟模型时,我得到相同的结果: irb(main):001:0> temp = NonPlayableApp.new( steam_id: 33333, name: “Testing” ) => # irb(main):002:0> temp.steam_id => 33333 irb(main):003:0> temp.name => “Testing” […]

Rails是否需要数据库级约束?

我遇到与以下post相同的问题。 所以我想知道,为什么Rails默认不支持生成外键? 不是必要的吗? 或者我们应该手动完成吗?

向Rails的狂欢电子商务添加路由

我刚刚升级到1.0.3 ,我的config / routes文件夹中的routes.rb文件似乎忽略了我的所有自定义路由。 我的routes.rb JollyStore::Application.routes.draw do # Mount Spree’s routes mount Spree::Core::Engine, :at => ‘/’ root :to => ‘pages#index’ namespace :admin do resources :wysiwygs end match ‘about_us/’, :to => “pages#about_us” match ‘services/’, :to => “pages#services” match ‘raw_resources/’, :to => “pages#raw_resources” match ‘contact_us/’, :to => “pages#contact_us” match ‘privacy_policy/’, :to => “pages#privacy_policy” match ‘return_policy/’, :to => […]

显示特定用户的post?

这里我有一些代码: def show @post = Post.find() end end 用户模型有has_many:posts,post模型有belongs_to:user。 现在,我如何才能使show动作仅显示用户登录的post。登录的用户是“current_user”?

将PDF / Worddocs上传到应用程序Rails后获取“nil”

因此,我正在构建一个应用程序,用户可以在其中创建Pin并将图片和PDF / Word.docs上传到Pin 。 似乎我已经做了一切来启用这些选项; 在Pins模型中创建的方法: class Pin { :medium => “300×300>”, :thumb => “100×100>” } validates_attachment :image, content_type: { content_type: [“image/jpg”, “image/jpeg”, “image/png”, “image/gif”] } validates :image, presence: true has_attached_file :document validates_attachment :document, :content_type => { :content_type => %w(application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document) } end 在DB中生成迁移 class AddFileToPin < ActiveRecord::Migration def self.up change_table :pins do |t| […]

Schema.rb显示由于以下NoMethodError#undefined方法`’为nil:NilClass,因此无法转储表“progress”

我正在尝试使用Carrierwave添加一个多图像上传器, 然后 将文档添加到我的应用程序中。 通常我的schema.rb看起来像这样 ActiveRecord::Schema.define(version: 20160814232416) do create_table “progresses”, force: :cascade do |t| t.string “title” t.string “date” t.text “content” t.datetime “created_at”, null: false t.datetime “updated_at”, null: false end end 当我跑: rails g migration add_images_to_progresses images:json和rake db:migrate 我的架构改变并显示出奇怪的东西……是Sqlite3还是Pg的问题? 我该怎么办 ? ActiveRecord::Schema.define(version: 20160815005123) do # Could not dump table “progresses” because of following NoMethodError #undefined method `[]’ […]

Rake任务是否需要使用Resque在后台运行?

我在rake任务中有这个代码。 这似乎有点矫枉过正,因为rake任务已经作为一个cron工作运行了。 我想我可以安全地将它从Resque中取出并直接运行,但不确定我是否错过了什么。 desc “update daily sales” task :daily_sales => :environment do Resque.enqueue(DailySaleService.perform) end

无法选择created_at分组的行

我有桌子: +—-+———————-+———————+ | id | implemented_features | created_at | +—-+———————-+———————+ | 1 | 19 | 2013-07-18 04:10:12 | | 2 | 6 | 2013-07-18 04:10:12 | | 3 | 26 | 2013-07-19 04:10:12 | | 4 | 11 | 2013-07-19 04:10:12 | | 5 | 1 | 2013-07-20 04:10:12 | +—-+———————-+———————+ 当我通过My​​SQL直接查询它时,它可以完美地工作 select date(created_at) as […]

使用REST_CLIENT发出请求,相当于curl请求

我正在尝试使用rest_client来发出这个curl请求,并且我一直都弄错了。 我该怎么做? curl请求:它运行良好并从yahoo返回访问令牌。 curl -u “:” -d “grant_type=authorization_code&code=&redirect_uri=” https://api.login.yahoo.com/oauth2/get_token 我正在努力工作的rest_client请求是: # get token yahoo_url = “https://api.login.yahoo.com/oauth2/get_token/” response = RestClient::Request.new( :method => :get, :url => yahoo_url, :client_id => $consumer_id, :client_secret => $consumer_secret, :headers => { :accept => :json,:content_type => :json}, :params => {‘grant_type’ => ‘authorization_code’, ‘code’ => code, ‘redirect_uri’ => $yahoo_redirect_url} ).execute results = JSON.parse(response.to_str) puts […]