developer

Using fonts with Rails asset pipeline

Question: ❓❓❓ I have some fonts being configured in my Scss file like so: @font-face { font-family: 'Icomoon'; src: asset-url('icoMoon.eot?#iefix', font) format('embedded-opentype'), asset-url('icoMoon.woff', font) format('woff'), asset-url('icoMoon.ttf', font) format('truetype'), asset-url('icoMoon.svg#Icomoon', font) format('svg'); } The actual font file are stored in /app/assets/fonts/ I have added config.assets.paths << Rails.root.join("app", "assets", "fonts") to my Read more…

By admin, ago
developer

Rails where condition using NOT NULL

Question: ❓❓❓ Using the rails 3 style how would I write the opposite of: Foo.includes(:bar).where(:bars=>{:id=>nil}) I want to find where id is NOT null. I tried: Foo.includes(:bar).where(:bars=>{:id=>!nil}).to_sql But that returns: => "SELECT \"foos\".* FROM \"foos\" WHERE (\"bars\".\"id\" = 1)" That’s definitely not what I need, and almost seems like a Read more…

By admin, ago
developer

Rails :include vs. :joins

Question: ❓❓❓ This is more of a “why do things work this way” question rather than a “I don’t know how to do this” question… So the gospel on pulling associated records that you know you’re going to use is to use :include because you’ll get a join and avoid Read more…

By admin, ago
developer

How do I get the name of a Ruby class?

Question: ❓❓❓ How can I get the class name from an ActiveRecord object? I have: result = User.find(1) I tried: result.class # => User(id: integer, name: string ...) result.to_s # => #<User:0x3d07cdc>" I need only the class name, in a string (User in this case). Is there a method for Read more…

By admin, ago
developer

Rails update_attributes without save?

Question: ❓❓❓ Is there an alternative to update_attributes that does not save the record? So I could do something like: @car = Car.new(:make => 'GMC') #other processing @car.update_attributes(:model => 'Sierra', :year => "2012", :looks => "Super Sexy, wanna make love to it") #other processing @car.save BTW, I know I can Read more…

By admin, ago