Sass Syntax Error: wrong number of arguments (1 for 3) for `rgb' - ruby-on-rails

I use Ruby On Rails 5 and gem sass-rails 5.0
For some reason I get an error message:
wrong number of arguments (1 for 3) for `rgb'
in line number 2 of file app/assets/stylesheets/main.css.scss
$main-color-raw: rgb(0,80,170);
$main-color: rgb($main-color-raw);
$main-color-bright: rgba($main-color-raw, 0.5);
I tried with a hex color value instead of rgb():
$main-color-raw: #0050aa;
But get the same error message.
It looks like the sass-variable $main-color-raw is not evaluated correctly and maybe is the rails-sass gem configuration wrong.
So I added in my config/application.rb
config.sass.preferred_syntax = :scss
config.sass.line_comments = false
config.sass.cache = false
from the rails-sass github documentation page.
But still the same error.
How can I resolve it?

$main-color-raw: rgb(0,80,170);
so in $main-color, you've got:
$main-color: rgb(rgb(0,80,170));
so you are passing only 1 argument to rgb.
You should declare main-color-raw as:
$main-color-raw: 0, 80, 170;

Related

ArgumentError when running Capybara tests on Ruby 3.0

I am really stuck. I am upgrading my Rails app to Ruby 3 (from 2.7). When running tests, I always run into this issue when I visit a path:
state = "new"
visit status_path(state: “state")
I receive the following error when running rspec:
Capybara starting Puma...
* Version 5.6.4 , codename: Birdie's Version
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:58568
ArgumentError: wrong number of arguments (given 2, expected 1)
from ~/.rbenv/versions/3.0.5/lib/ruby/3.0.0/net/protocol.rb:116:in `initialize'
My Gemfile is as such:
gem "capybara" # 3.38.0
gem "selenium-webdriver" # 4.8.0
gem "webdrivers" # 5.2.0
(They're all on the latest version)
My setup doesn't look wrong:
require "webdrivers/chromedriver"
Webdrivers.cache_time = 86_400 # 1 day
Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |options|
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
end
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.javascript_driver = :headless_chrome
Troubleshooting:
I tried Puma 6 - same issue.
The controllers at status_path is not even hit. This errors occurs right after Puma loads up.
I do not think it's the Capybara setup, and I just cannot find where it is calling the Ruby 3 library wrong (net/protocol).
I downgraded capybara to 3.37.1, and same issue.
Thank you
FYI Upgrading from 2.7 to 3 you will more often than not see this error. It's highly likely that some code you were previously using in 2.7 will be not correctly hashing some args.
The first hit when googling this will take you back to SO (Won't share link as SO doesn't like links). But to paraphrase from the official ruby byline when updating
Separation of positional and keyword arguments in Ruby 3.0:
In most cases, you can avoid incompatibility by adding the double splat operator. It explicitly specifies passing keyword arguments instead of a Hash object. Likewise, you may add braces {} to explicitly pass a Hash object, instead of keyword arguments.
TL;DR - Try doing splatting your hash args collection kwargs -> **kwargs - Your rails path likely isn't a kwarg but a hash --> { key: value }
EDIT: Reasoning (If you're interested), is that prior to ruby3. Ruby would try assess and guesstimate what you meant. From ruby3 onwards it has made a change and fill forcibly use what you give it (A lot of people used to use kwargs but wanted them treated as a single hash, now you need to stipulate this!)

How to alias a table name?

Since upgrading to Rails 5 I have a query that is not working. It is unable to get results from a table by its alias. The error is that "from" takes zero arguments now. The version of arel is 9.0, the version of Rails is 5.2.4.3
offers = Offer.arel_table
o2 = offers.alias("o2")
seen_offers = offers.from("offers as o2").project(o2[:merchant_id], o2[:display_name])
this is the error:
ArgumentError: wrong number of arguments (given 1, expected 0)
Arel::Table#from takes 0 arguments because it generates a SelectManager:
SelectManager.new(self)
What you are looking for is SelectManager#from and the issue is easily correctable (just switch the project and the from)
offers.project(o2[:merchant_id], o2[:display_name]).from(o2)
project will return a SelectManager and then from will simply change the source

Unable to check response size with Rack Deflater

I'm trying to use Rack::Deflater to compress responses when the body is greater than 512 bytes in size.
Using the example given in the latest Rack Deflater source code in my config.ru I get the following error:
/gems/rack-1.5.5/lib/rack/deflater.rb:20:in `initialize': wrong number
of arguments (2 for 1) (ArgumentError)
Any idea what I'm doing wrong here? Any documentation I've found online suggests the syntax I'm using is correct. I'm using RoR 4 and Rack 1.5.5.
This is my config.ru file in its entirety:
require ::File.expand_path('../config/environment', __FILE__)
require 'rack'
use Rack::Deflater, :if => lambda { |*, body| sum=0; body.each { |i| sum += i.length }; sum > 512 }
run Rails.application
I suspect it's some kind of versioning error but I'm unsure.
Yes, you are right. It's version issue. You paste code from the very last version (2.0.3/2.0.4), but according to your trace you have 1.5.5 in your local setup.
Here you can see that Rack::Deflater doesn't accept any additional options in 1.5.5 -- https://github.com/rack/rack/blob/1.5.5/lib/rack/deflater.rb#L20
Firstly options were added in the very next release 1.6.0.beta. You can see that here -- https://github.com/rack/rack/blob/1.6.0.beta/lib/rack/deflater.rb#L28
Updating your rack should solve your issue for you

postgres - operator does not exist: double precision ~~ unknown

ActionView::Template::Error (PG::UndefinedFunction: ERROR: operator
does not exist: double precision ~~ unknown
2016-04-10T23:45:59.506005+00:00 app[web.1]: LINE 1: ... =
"trackers"."category_id" WHERE (categories.tag LIKE '1.%'...
this is the error i get when i try to run this line of code here
Tracker.group(:category_id).joins(:category).where('categories.tag LIKE ? AND user_id = ?', "#{tag.to_i}.%", current_user.id)
tag is of type float, and i typecast it to an integer in order to check for tags 1.1, 1.2, 1.3 etc
so in the example above I type cast tag with value 1.0 to be 1, so i can search for tags that are like 1.1, 1.2 etc
I am using postgres on heroku that gives this error. locally i use sqlite3 and it works just fine.
how can i overcome this?
Since you're in rails, sort out the dynamic-ness in rails first then send that to the ORM. The syntax you provided already accepts any parameters (eg: WHERE tag between ? and ?), so before you request the data from the ORM, sort out in rails the high and lows. The query is already setup for something to be dynamic.

invalid multibyte escape after upgrade to rails 3 and ruby 1.9.2 -- dtext = '[^\\x80]'

I am upgrading my app from rails 2 to 3 and when i 'require' this file that has an email address validator i get an 'invalid multibyte escape' error with:
dtext = '[^\\\\x80]'
pattern = /\A#{dtext}\z/
Any thoughts?
Try using:
pattern = /\A#{dtext}\z/, nil, 'n'
Check out details on encodings and regexp for more.
And I use and recommend this awesome article on encodings in Ruby.
Modify the rfc822.rb file and change the addr_spec line to the following:
addr_spec = Regexp.new("#{local_part}\\x40#{domain}", nil, 'n')
That should resolve the issue. I got the solution from another gem, see https://github.com/saepia/rfc822/blob/master/lib/rfc822.rb

Resources