Seeding file uploads with CarrierWave, Rails 3

Turns out the documentation for CarrierWave is slightly wrong. There is a more up to date piece of code in the README at the GitHub repository for the project. In a nutshell, though: pi = ProductImage.create!(:product => product) pi.image.store!(File.open(File.join(Rails.root, ‘test.jpg’))) product.product_images << pi product.save!

Download all gems dependencies

That’s precisely the problem I had. After searching around for a while I found a solution that works using Bundler https://bundler.io/ Getting Gem with Dependencies: Create a new Folder with a File named Gemfile. Write a Source and the Gem you want to have the dependencies for into the File Example: source “http://rubygems.org” gem ‘rails’, … Read more

error: failed to build gem native extension when installing rails on mac mountian lion os

I see that you are using ruby 1.9.3 using rvm on OS X 10.8.2 (Mountain lion) It’s possible that some gems referenced by rails need gcc-4.2 in /usr/bin to build native estension. In Mountain Lion , even after installing Xcode 4.5 CLI tools ( opening the menu XCode – Preferences..Download -> Command Line Tools ) … Read more

RSpec testing redirect to URL with GET params

From the documentation, the expected redirect path can match a regex: expect(response).to redirect_to %r(\Ahttp://example.com) To verify the redirect location’s query string seems a little bit more convoluted. You have access to the response’s location, so you should be able to do this: response.location # => http://example.com?foo=1&bar=2&baz=3 You should be able to extract the querystring params … Read more

Ruby’s double colon (::) operator usage differences

Constants in Ruby are nested like files and directories in filesystem. So, constants are uniquely identified by their paths. To draw an analogy with the file system: ::Rails::Engine #is an absolute path to the constant. # like /Rails/Engine in FS. Rails::Engine #is a path relative to the current tree level. # like ./Rails/Engine in FS. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)