The differences between .build, .create, and .create! and when should they be used?

So I've been seeing people using .build, .create, and .create! within their controllers more and more lately. What's the difference from just using .new and passing the param'd object and then...

UTF-8 characters mangled in HTTP Basic Auth username

I'm trying to build a web service using Ruby on Rails. Users authenticate themselves via HTTP Basic Auth. I want to allow any valid UTF-8 characters in usernames and passwords. The problem is...

Get person's age in Ruby

I'd like to get a person's age from its birthday. now - birthday / 365 doesn't work, because some years have 366 days. I came up with the following code: now = Date.today year = now.year -...

Log every SQL query to database in Rails

I want to save to a log file some SQL query rails performs, (namely the CREATE, UPDATE and DELETE ones) therefore I need to intercept all queries and then filter them maybe with some regexp and...

Detect screen size and pixel density on the server-side?

I've been doing some research and I think I know the answer already, but I'm wondering if there's any means by which you can get a device's screen size and pixel density without the use of...

Rails nested_form link_to_add not working when pre-building nested model instance

I'm having a rough go integrating ryanb's awesome nested_form gem into my rails 3.1.3 application. I'm afraid my Javascript skills are too limited to know whether it's my code (likely) or the gem...

Render JSON instead of HTML as default?

I try to tell rails 3.2 that it should render JSON by default, and kick HTML completely like this: respond_to :json def index @clients = Client.all respond_with @clients end With this...

Can't start elasticsearch server via Homebrew

So I have installed elasticsearch through brew: $ brew install elasticsearch Then when I run the elasticsearch server: elasticsearch -f -D...

Find records where an attribute is present

I have a User model with the attributes username, email and name. username and email are required upon signup, but not name. What would be the query to find all users that have filled out name...

How to use new_record?, changed? and persisted? methods in rails in this example

Trying to undestand new record?,changed ? and persisted ? on the example below. How, this code has this result: # NOW # there is 0 new record after running new_data array # there is 0 changed...

Authenticate Devise User Before Accessing Omniauth Routes

I'm developing an app that utilizes devise for my user records and omniauth for records owned by the user, rather than using the typical omniauth + devise for user records. I'm trying to add...

Heroku Scheduler not creating log

I recently set up the Scheduler add on and set up my rake task, 'rake cron_jobs:my_task'. When I test it with 'heroku run rake cron_jobs:my_task', it works fine. The scheduler also claims it ran...

Rails: permission denied for relation schema_migrations

I'm trying to setup a local production environment for a Ruby on Rails web application. I can run the application with rails server command, which gives the development environment. The production...

ActiveRecord::StatementInvalid: Mysql2::Error: Lock wait timeout exceeded

In my rails project, I use sidekiq processing time consuming task, but in sidekiq log an error: ActiveRecord::StatementInvalid: Mysql2::Error: Lock wait timeout exceeded; try restarting...

HTTP POST request with JSON payload from react app returns net::ERR_SSL_PROTOCOL_ERROR(chrome)

I have a react app that makes API call to the endpoint http://localhost:3020/schema/filter. Following is the payload that I am passing with the POST request. `let filterParams = { ...

What is the `__identify__` route that Capybara looks for?

When I disable Webmock or VCR I get the following error in my Rspec tests. Apparently it's looking for an /__identify__ route. WebMock::NetConnectNotAllowedError: Real HTTP...

An error occurred while installing mysql2 (0.4.8), and Bundler cannot continue

How can I fix this error in ruby on rail. source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") ...

What does %i or %I do in Ruby?

What's the meaning of %i or %I in ruby? I searched Google for "%i or %I" ruby but I didn't find anything relevant to Ruby.

Rails how to debounce background task?

Debouncing is a common method to postpone a function/job from executing until after certain time has passed. Use-case: A conversation with active chatting from multiple users, they should not...

Trying to install RVM and getting: Error running '__rvm_make -j2'

I was trying to install RVM with stable ruby on a mac and got a make error: abbreviated console output: \curl -sSL https://get.rvm.io | bash -s stable --ruby\curl -sSL https://get.rvm.io ...

Webpacker::Manifest::MissingEntryError

I've started a rails project using rails new with --webpack=react. I generated a new controller updated my PostgreSQL password in the database.yml. Up to this point, everything works fine. At this...

fatal: could not read Username for 'https://github.com ': No such device or address - rubyonrails - aws

I have a rubyonrails website which function in such a way that when a user signup with his username it create a repo in that username in my github account. It is working flawlessly in heroku. When...

Paperclip alternative that works in Rails 4 and Rails 6

Background We have a legacy, monolith Rails 4.2 project. Call it "Classic." "Classic" uses Paperclip for dealing with the storage of assets (photos, attachements, etc.) in a 3rd-party system. We...

Rails wikedPDF Error: PDF could not be generated

I'm trying to use WikerdPdf on rails 6 but I'm having this error RuntimeError (Failed to execute: ["/home/guilherme/.rbenv/versions/2.7.1/bin/wkhtmltopdf",...

How do I fix this error: "Your bundle only supports platforms [] but your local platforms are ["ruby", "x86_64-darwin-19"], and there's no compati..."

When I run bundle install this is the response I get "Your bundle only supports platforms [] but your local platforms are ["ruby", "x86_64-darwin-19"], and there's no compatible match between...

Rails 6 API + React + Google login: how to authorize user to access certain server routes after login?

Please let me know if you need more information. I'm building a website with a React frontend and Rails 6, which is in api-only mode. I've added Google login to the frontend using the...

Rails 6.1 How to Render A FIle Into A Page Template

This used to work - render file: "public/404.html", status: :not_found After updating to Rails 6.1, it no longer works with this error - render file: should be given the absolute path to a file....

Active Admin won't install: superclass mismatch for class StringIO (TypeError)

I was recently trying to install Active Admin but it keeps producing this error below. I have added activeadmin, devise, draper, cancancan, and pundit to the gemfile. For reference, I am trying to...

Rails bundle install Could not find turbo-rails-7.1.1 in any of the sources

On a brand new digitalocean droplet running Ubuntu 20.10 with a brand new pretty near empty rails 7 alpha 2 app running bundle install results in the following both when running cap production...

With Rails 4.2 and lograge, how do I enable date/times before each logged line?

I use the gem “Lograge” 0.3.6, and Rails 4.2. I have this configured in my config/environments/development.rb file config.lograge.enabled = true config.lograge.formatter =...