#RubyOnRails - 19 November 2018
« Back 1 day Forward 1 day »
[11:30:38] gavit: execjs seems to support nodejs, however I can't find any documentation on how to make nodejs integrate with rails, do I need to add a gem etc, or should I just install nodejs and it should work out of the box
[11:49:46] adgtl: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email"
[11:49:48] adgtl: : INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2018-11-19 11:49:08.706871', '2018-11-19 11:49:08.706871', 298486374)
[16:49:07] Aces1up: hey all i have been searching around but can not find an answer to this. when i save a datetime to column in rails I know it saves it as utc.. How can I later do a query on that datetime to see if it has passed a certain time in another timezone?
[16:49:47] Aces1up: it is as simple as querying the database using a datetime object set with a different timezone and AR knows what to do from there?
[18:02:38] tubbo: AR is gonna convert the UTC timestamps into the timezone specified by rails in your config
[18:02:59] tubbo: but you can get it to convert to another timezone by using #in_time_zone. https://api.rubyonrails.org/v5.2.1/classes/ActiveSupport/TimeWithZone.html#method-i-in_time_zone
[19:20:22] tubbo: quarters: well, what i meant by "private gem source" was a server, like https://gems.yourcompany.com
[19:43:20] quarters: I'm guessing that gems in a gemfile aren't installed in a rails project but installed in the ruby folder? if so, if there are projects that use different versions of the same gem, are they all installed in that ruby folder?
[19:50:55] tubbo: quarters: it depends, you can pass `--path` or set `$BUNDLE_PATH` to configure the folder that bundler keeps gems in. i think it keeps your gems in the shared location defined by rubygems ($GEM_HOME) by default, though.
[19:51:18] tubbo: and it's separated by version so you can in theory have multiple versions of the same gem installed side-by-side...bundler will pick the right version for your app
[20:35:27] tubbo: that will update all records that match the query in one big INSERT INTO i believe
[21:27:08] jayjo: I'm trying to deploy an application into a subdirectory instead of rootlevel, is the variable RAILS_RELATIVE_ROOT_URL all I need to compile when I do bundle exec rake assets:precompile
[21:27:57] jayjo: and does that variable matter if it is /subdir or /subdir/ - will either make a difference?
[21:40:06] quarters: when I try to run rails db:migrate on the following: I get an error "wrong number of arguments (2 for 1)" and was wondering how to fix it: https://pastebin.com/Sy3MxL07
[21:41:35] Doddlin: Radar, might have found it https://stackoverflow.com/questions/26326660/saving-data-with-medium-editor-rails
[21:42:55] roamingdog: Radar: you no longer maintain logs for #rubyonrails? know where i can see them?
[21:44:10] roamingdog: Radar: thanks, don't see it in channel announcement so i'll bookmark it somewhere
[21:44:43] Radar: roamingdog: Weird. I thought we had it in the topic, but I guess it's not there anymore.
[21:46:18] Radar: quarters: I don't get why it's pointing at this line: https://github.com/rails/rails/blob/v5.2.1/activerecord/lib/active_record/inheritance.rb#L15
[21:46:44] Radar: Stacktrace line before that points to protected_attributes_continued-1.3.0. I wonder if that is to blame somehow.
[21:47:46] Radar: roamingdog: If you're interested in the source for that app, it's here: https://github.com/radar/logs.ex. But it's Phoenix, not Rails because I am a traitor ;)
[21:48:07] quarters: Radar, I added protected attributes continued to be able to keep the syntax for attr_accessible from legacy code
[21:48:38] Radar: roamingdog: I did... but then I was learning Phoenix and wanted a small app to write and picked this one. It's only about 15x faster than the Rails equivalent.
[21:49:53] quarters: Radar: removing that gem will lead to other breakage and I was wondering if there's a way to troubleshoot without removing that gem
[21:50:16] Radar: quarters: Well, I would find out what /home/user/.rvm/gems/jruby-18.104.22.168/gems/activerecord-5.2.1/lib/active_record/inheritance.rb:15 is.
[21:50:31] Radar: quarters: But When I looked into Rails source, it's a comment. So that's not right. Something's weird there.
[21:53:02] Radar: quarters: https://github.com/westonganger/protected_attributes_continued/blob/master/lib/active_record/mass_assignment_security/validations.rb#L15
[21:54:20] Radar: quarters: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/inheritance.rb#L50
[21:54:31] Radar: quarters: I believe it's getting to this line, and the stacktrace is pointing to the wrong line.
[21:54:51] Radar: quarters: notice that the method definition there only takes one argument and a block. So it seems like protected_attributes_continued is wrong.
[21:55:02] Radar: https://github.com/rails/rails/blob/v5.2.1/activerecord/lib/active_record/inheritance.rb#L50
[21:55:29] Radar: https://github.com/rails/rails/blob/v5.0.4/activerecord/lib/active_record/inheritance.rb#L48 <- different method sig in older 5.x versions
[21:55:46] Radar: quarters: so I'd say protected_attributes_continued is not compatible with Rails 5.2.1.
[21:56:19] Radar: Latest 5.1 also has the same signature as 5.0.x: https://github.com/rails/rails/blob/v5.1.6/activerecord/lib/active_record/inheritance.rb#L49
[21:56:37] Radar: The gem also does not include 5.2 in its .travis.yml list: https://github.com/westonganger/protected_attributes_continued/blob/master/.travis.yml#L10-L14
[21:57:10] Radar: quarters: What I'd do here is to fix how protected_attributes_continued is calling that method, passing the right number of arguments (whatever those are) and then submit a patch upstream. In the meantime, use your own fork of that gem (with the fix) and that should make your problems go away.
[22:11:34] quarters: does that mean that validation does not happen through constraints in the database?
[22:26:59] Radar: quarters: perhaps take this as a sign that you should be moving away from attr_accessible? :)
[22:28:39] quarters: Radar: I'll definitely wean off of it but I'm a bit confused about how activerecord no longer accepts an options argument but https://edgeguides.rubyonrails.org/active_record_migrations.html says that it still accepts options arguments in migration files
[22:29:04] quarters: I'm not sure if the edgeguides are just not updated and I'll have to find what the current api for migrations is
[22:31:38] Radar: quarters: It's not migrations. It's when it goes to save the info to the schema_migrations table in the database, it uses AR's own `create`, which then relies on `new`.