config.assets.compile=true in Rails production, why not?

The default Rails app installed by rails new has config.assets.compile = false in production. And the ordinary way to do things is to run rake assets:precompile before deploying your app, to make sure all asset pipeline assets are compiled. So what happens if I set config.assets.compile = true in production? I wont’ need to run … Read more

Rails: Installing PG gem on OS X – failure to build native extension

It seems many others have had problems installing the pg gem. None of the solutions posed for others have worked for me. I have tried to install the pg gem and postgres.app. The pg gem won’t install. The first error I get is: An error occurred while installing pg (0.17.0), and Bundler cannot continue. Make … Read more

Unable to install gem – Failed to build gem native extension – cannot load such file — mkmf (LoadError)

Ruby 1.9.3 The part of Gemfile #…………… gem “pony” gem “bcrypt-ruby”, :require => “bcrypt” gem “nokogiri” #……………… When I’m trying to install gems, I get an error alex@ubuntu:~/$ bundle Fetching gem metadata from http://rubygems.org/……… Fetching gem metadata from http://rubygems.org/.. Enter your password to install the bundled RubyGems to your system: #####…………………………………………………… Installing bcrypt-ruby (3.0.1) with … Read more

invalid multibyte char (US-ASCII) with Rails and Ruby 1.9

I’m using Ruby 1.9.1 with Rails 2.3.4 My application is to handle text input If I try something like (the inside quotation marks look different) text = “”“” I get the following error: #<SyntaxError: /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII) /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII) /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: syntax error, unexpected $end, expecting keyword_end I need to user … Read more

Generate model in Rails using user_id:integer vs user:references

I’m confused on how to generate a model that belongs_to another model. My book uses this syntax to associate Micropost with User: rails generate model Micropost user_id:integer but https://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration says to do it like this: rails generate model Micropost user:references The migrations generated by these 2 are different. Also, for the former, how does rails … Read more

Rails 4 Authenticity Token

I was working on a new Rails 4 app (on Ruby 2.0.0-p0) when I ran into some authenticity token problems. While writing a controller that responds to json (using the respond_to class method), I got to the create action I started getting ActionController::InvalidAuthenticityToken exceptions when I tried to create a record using curl. I made … Read more

Rails ActiveRecord date between

I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select. How can I use ActiveRecord to do that? I need something like: “SELECT * FROM comments WHERE created_at BETWEEN ‘2010-02-03 00:00:00’ AND ‘2010-02-03 23:59:59′” 11 Answers 11

Rails: How do I create a default value for attributes in Rails activerecord’s model? [duplicate]

This question already has answers here: Rails: How can I set default values in ActiveRecord? (29 answers) Closed 8 years ago. I want to create a default value for an attribute by defining it in ActiveRecord. By default everytime the record is created, I want to have a default value for attribute :status. I tried … Read more