ruby-on-rails-3.1

Errno::ENOENT (No such file or directory) in amazon-s3

我与影子孤独终老i 提交于 2019-12-01 03:43:46
问题 I have application which is deployed to heroku using amazon s3 posting images to buckets.This works perfectly fine. But when fetching same image it gives error: Errno::ENOENT (No such file or directory showing path s3.amazonaws.com/bucket_name/app/public/messages/images/000/000/061/thumb/images.jpeg?1362410115) Same path copying and pasting in browser's url doesn't work. If I am using bucket name as end point it works ie, with following path /bucket_name.s3.amazonaws.com/app/public/messages

Rails 3.1: accepts_nested_attributes_for and has_one association - won't work?

让人想犯罪 __ 提交于 2019-12-01 03:42:22
I'm trying to use accepts_nested_attributes_for on a has_one association model, and getting absolutely nowhere :-( I have two models, a user and a location. A user has one location: class User < ActiveRecord::Base # current location has_one :location, :dependent => :destroy accepts_nested_attributes_for :location end class Location < ActiveRecord::Base belongs_to :user end I can save changes to the model by using User.find(1).location.current_location_text = "blah" from the console, so I know the associations are set up correctly. I have two forms on the edit user page. One that updates the

Rails 3.1 assets has no fingerprint in production

半腔热情 提交于 2019-12-01 03:37:45
Just started to adapted to rails 3.1, I started to write coffeescript and sass and everything works fine in development. When I run the server in production, I only get: <link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" /> <script src="/javascripts/application.js" type="text/javascript"></script> in the source code of the page, there's no hashcode generated and both assets has routing errors: Routing Error No route matches [GET] "/stylesheets/application.css" What's the cause of this? Did I forget to do something? settings in environments/production.rb :

Why are my RSpec tests failing, but my app is working?

▼魔方 西西 提交于 2019-12-01 03:33:47
I just finished chapter 10 of the Ruby on Rails Tutorial , adding the ability to edit/update, index, and destroy users. Everything appears to be working properly in my app, but many of my tests are failing when I run RSpec. I have the users_controller_spec set up exactly as the book does it and my application code is the same as well. Could one issue may be that I am using Rails 3.1.1 as opposed to Rails 3.0 which he uses in the book? It hasn't really been an issue for previous tests, just occasionally for a few different lines of code. The issues started appearing after I started section 10.2

Rails - Devise, how can I disable some default routes?

允我心安 提交于 2019-12-01 02:09:17
I want to completely disable the routes /users/sign_in for get and post. I was able to successfully override them using the following: devise_for :users do get "/admin" => "devise/sessions#new", :as => :new_user_session post "/admin" => "devise/sessions#create", :as => :user_session end And when I run rake routes I see the following: new_user_session GET /admin(.:format) {:controller=>"devise/sessions", :action=>"new"} user_session POST /admin(.:format) {:controller=>"devise/sessions", :action=>"create"} new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise

(Object doesn't support #inspect)

假如想象 提交于 2019-12-01 02:09:02
问题 I have a simple case, involving two model classes: class Game < ActiveRecord::Base has_many :snapshots def initialize(params={}) # ... end end class Snapshot < ActiveRecord::Base belongs_to :game def initialize(params={}) # ... end end with these migrations: class CreateGames < ActiveRecord::Migration def change create_table :games do |t| t.string :name t.string :difficulty t.string :status t.timestamps end end end class CreateSnapshots < ActiveRecord::Migration def change create_table

Rails how to sum columns?

隐身守侯 提交于 2019-12-01 02:04:21
Example I have: @test = Pakke.find([[4], [5]]) In my Pakke table I have a column named prismd How do I sum the two values for the prismd columns for @test? Holger Just You can summarize directly on the database by creating the respective SQL like this: Pakke.sum(:prismd, :conditions => {:id => [4,5]}) See ActiveRecord::Calculations for more usage examples and general documentation. ActiveRecord has a bunch of built-in calculation methods, including sum : @test = Pakke.where(:id => [4, 5] ).sum(:prismd) Rails beginner Pakke.find([[14], [15]]).map(&:prismd).sum test = Order.where(potential

ruby on rails how to deal with NaN

爷,独闯天下 提交于 2019-12-01 02:03:13
I have read few posts regarding NaN but did not figure out how to deal with it in Ruby on Rails. I want to check a value if it is a NaN I want to replace it with Zero(0). I tried the following logger.info(".is_a? Fixnum #{percent.is_a? Fixnum}") when percent has NaN it returns me false. I have made few changes in the logger logger.info("Fixnum #{percent.is_a? Fixnum} percent #{percent}") Output Fixnum false percent 94.44444444444444 Fixnum false percent NaN Fixnum false percent 87.0 NaN is instance of Float . Use Float#nan? method. >> nan = 0.0/0 # OR nan = Float::NAN => NaN >> nan.class =>

Asset pipeline encoding problems (UTF-8 vs. ASCII-8BIT) with external gem

眉间皱痕 提交于 2019-12-01 01:20:19
问题 I'm trying to create a gem that wraps d3.js, Source can be found at https://github.com/iblue/d3-rails So when I include this gem in my Gemfile gem "d3-rails", :git => "git://github.com/iblue/d3-rails.git" And when I include the javascript in my application.js: //=require d3 Then my asset compilation fails and my compiled application.js just contains throw Error("Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT") I am using Rails 3.1.3 and ruby-1.9.3-p125.

Ruby on Rails 3.1 assets:precompile and images

别来无恙 提交于 2019-12-01 01:14:10
问题 I can't get the Rails 3.1 asset pipeline precompilation to work in production mode. It always fails on images referenced within SCSS with an error like: $ bundle exec rake assets:precompile RAILS_ENV=production rake aborted! rails.png isn't precompiled (in /home/florian/AssetTest/app/assets/stylesheets/application.css.scss) But when I look in the public/assets directory, the image is there, so it is precompiled: $ ls public/assets | grep rails rails-dd352fc2630e5f9aa5685ef1d7fe5997.png The