tbuehlmann

Activity Graph

« Prev | Page 2 of 45 | Next »

2019-02-06

[09:57:58] tbuehlmann: `SomeModel.first.inspect` displays timestamps using the database configured timezone, not the application configured timezone. `SomeModel.first.created_at` correctly displays the timestamp using the application timezone, as expected. the code for the inspection is here: https://github.com/rails/rails/blob/v5.2.2/activerecord/lib/active_record/attribute_methods.rb#L352
[09:58:05] tbuehlmann: any idea why that would be useful?
[13:00:11] tbuehlmann: guyzmo: "first" an in ordered by foobars.created_at DESC?
[13:17:07] tbuehlmann: could be this: A.joins(:foobars).order(as.id, foobars.created_at).select('DISTINCT ON(projects.id) projects.*').where(foobars: {title: nil})
[13:17:34] tbuehlmann: although that might be wrong, I'm not sure whether where is applied before or after distinct on :\
[13:30:22] tbuehlmann: guyzmo: is the foobar_position absolut? as in: the first foobar has foobar_position 0?
[13:31:10] tbuehlmann: greengriminal: wanted to write that, I think that's the case
[13:35:49] tbuehlmann: if you only care about the presence of any number, go for `bar_id`. if you care about the presence of the actual foreign record, got for `bar`. either way, you shoud have a foreign key constraint on your database
[13:55:57] tbuehlmann: guyzmo: tell me you're using postgres
[13:59:07] tbuehlmann: got something for you then, just a sec
[14:03:13] tbuehlmann: trickier than expected given that there's a join
[14:09:07] tbuehlmann: A.from('(SELECT as.*, foobars.x AS foobar_x, row_number() OVER (PARTITION BY as.id ORDER BY foobars.created_at DESC) FROM as INNER JOIN "foobars" ON "foobars"."project_id" = "as"."id") as').where(row_number: 1, foobar_x: nil)
[14:09:42] tbuehlmann: I used two of my sandbox models and renamed them to A/as and foobars. this will probably crash as "AS" has a certain meaning in SQL. but you'll get the idea
[14:10:54] tbuehlmann: I'm using a partition so each group of foobars per a get a row_number (1, 2, 3, ...). having that, you can simply do a where(row_number: 1, foobar_x: nil). that foobar_x thingy is a bit hacky and there's probably a better way, but it worked in my example
[14:13:28] tbuehlmann: you're welcome :)
[14:17:23] tbuehlmann: it changes the FROM part of the query
[14:21:08] tbuehlmann: when Foo.has_many :bs: Foo.where(B.select(:a_id))
[14:21:17] tbuehlmann: this will only be one query (including a subquery)
[14:21:33] tbuehlmann: eh, :foo_id, not :a_id :)

2019-02-05

[13:11:11] tbuehlmann: sure, fix the code
[13:15:27] tbuehlmann: have you read the thread? when following the trail, you'll get to this: https://github.com/plataformatec/devise/commit/1009096172f2cbc86bcd54d053c89a09be67fb9f

2019-02-03

[10:59:03] tbuehlmann: timwis: can you gist your Gemfile?
[11:05:23] tbuehlmann: okay, so '~> 5.2.0' will let you upgrade to 5.2.2, is that good enough?
[11:07:19] tbuehlmann: right, so you can upgrade to 5.2.2. I don't know githubs security policy on activestorage. what version do you need?
[11:10:52] tbuehlmann: `bundle update rails` should update unless another gem dependency prevents it
[11:11:11] tbuehlmann: you can try setting the version to '5.2.2' and try again
[11:13:07] tbuehlmann: what does `bin/rails -v` display? are you on 5.2.2 already?

2019-02-01

[12:03:18] tbuehlmann: iirc, it returns the symbol's characters as String#[] does
[12:13:48] tbuehlmann: xco: don't use the `index: true` option but rather use add_index and use a custom index name
[13:56:53] tbuehlmann: "rails also sucks ballz" is a pretty harsh statement, it works for quite some people and companies
[13:57:42] tbuehlmann: so does php, right. I also don't think php sucks ballz

2019-01-31

[08:44:55] tbuehlmann: the producer threads puts items in the queue and the consumer threads takes items out of the queue. if a program reaches the end of the file, the program will exit and the threads will be killed, even if they are still doing their things. if you want to wait for the threads to finish their things, you can call .join on them, that's what it's for
[08:49:55] tbuehlmann: right, threads run concurrently to your main thread. they will be killed when the program is exited, though, they don't continue
[09:26:14] tbuehlmann: I put mine in lib/wsdls

2019-01-30

[10:17:54] tbuehlmann: keanny479: hey! what exactly do you mean, to "rewrite" the instance variables?
[10:23:32] tbuehlmann: nah, that's fine

2019-01-29

[10:14:08] tbuehlmann: https://pbs.twimg.com/media/Bn8ZYxrIMAIBMG3.png:large
[10:18:44] tbuehlmann: nah, the question is just loaded
[10:48:02] tbuehlmann: I don't understand your second sentence
[10:49:08] tbuehlmann: if it's `Foo.has_many :bars` and you want all foos with associated bars, that'd be an inner join: Foo.joins(:bars)
[10:49:25] tbuehlmann: that might return double foos, so you might want to use a distinct
[10:52:08] tbuehlmann: ntt: you can certainly do that. if these defaults are always the same, you could also use after_initialize in your model to set default value
[10:53:39] tbuehlmann: https://gist.github.com/tbuehlmann/0c36c0ac0e81de8b20f54879d3e42227 this will set some_attribute to 'default value' unless it's there
[10:54:01] tbuehlmann: with this, you can simply pass your params into the initializer
[10:55:37] tbuehlmann: if the defaults are always the same, you'd just put them into after_initialize, or am I missing something?
[10:55:55] tbuehlmann: (a different option is to have these defaults as database table defaults, btw)
[10:59:31] tbuehlmann: without the renaming this would simply be: `DeliveryRound.has_many :destinations, through: :missions`. so some_delivery_round.destinations would work
[11:02:18] tbuehlmann: sure, something like this then: https://gist.github.com/tbuehlmann/0c36c0ac0e81de8b20f54879d3e42227
[11:04:00] tbuehlmann: you could replace that hash in line 4 with whatever you have
[11:05:55] tbuehlmann: some_object.public_send(:foo) is like calling some_object.foo
[11:06:11] tbuehlmann: it let's you dynamically call methods on an object using a symbol
[11:08:48] tbuehlmann: you're welcome!
[13:55:56] tbuehlmann: I don't see anything suspicious

2019-01-26

2019-01-25

[14:04:59] tbuehlmann: reminder_text and reminder_date are table columns?
[14:05:34] tbuehlmann: great, remove that `attr_accessor :reminder_text, :reminder_date` and try again
[14:06:39] tbuehlmann: exactly. rails will check the database tables for the columns and add methods on the model. you're overriding the methods here
[14:08:20] tbuehlmann: you're welcome!
[14:08:36] tbuehlmann: nah, it's an honest mistake
[14:14:35] tbuehlmann: great gist for debugging this issue, btw. it's not every day that we get such good information

2019-01-24

[09:45:38] tbuehlmann: are you looking to slow down the requests? I can help with that
[10:43:09] tbuehlmann: kidPalooma: could reproduce, I'm checking
[10:55:38] tbuehlmann: kidPalooma: you're inheriting from Exception, but that should be StandardError
[10:59:41] tbuehlmann: technically they are still exceptions, but that could probably be more clear. you could open up an issue for this

2019-01-18

[07:37:05] tbuehlmann: makara: remove those spaces before/after ( and )
[07:40:23] tbuehlmann: the following will not raise an error: def index_for(words, word); end; index_for(%w{Mary had a little lamb}, "little")

2019-01-15

[08:11:19] tbuehlmann: havenwood: heh
[11:51:51] tbuehlmann: what's the problem with strings containing newlines?
[12:23:15] tbuehlmann: sunsea: you don't need a lot of math to get started
[13:32:10] tbuehlmann: za1b1tsu: when having a jsonb column, you'll work with a simple array

2019-01-14

[09:55:54] tbuehlmann: alexterziev: can you gist the stacktrace for that error? what line causes it?
[10:04:28] tbuehlmann: what's in app/controllers/application_controller.rb:214?
[10:11:56] tbuehlmann: looks to me like you're calling BigDecimal.new somewhere with a hash instead of a string

2019-01-12

[08:40:50] tbuehlmann: THKitten: what user runs your rails app/sidekiq process and what permissions does this user have on the pid file?
[10:12:46] tbuehlmann: take my like
[12:00:59] tbuehlmann: catbusters: `ProductDetails.belongs_to :product` sounds right to me. it depends on the product being there
[12:12:18] tbuehlmann: run `ls -l <path to file>` and see what user is mentioned there
[12:41:50] tbuehlmann: THKitten: get to go. I assume there's something with the permissions or user that's executing. good luck with that

2019-01-11

[08:20:48] tbuehlmann: IGnorAND: you could get a list of latest fights per boxer, something like Fight.order(match_date: :desc).select('DISTINCT ON (boxer_id) *'). this would order fights by match_date and only take the first one per boxer_id
[10:11:41] tbuehlmann: Spaceman77: is this about regular view rendering?
[10:24:11] tbuehlmann: Arkentias: haven't seen that before but could reproduce. adding `, on: :member` helps, though
[10:54:26] tbuehlmann: catbusters: you should have a higher concurrency than 1 either way
[10:55:47] tbuehlmann: something like that, yes. it might differ per app, though
[10:59:46] tbuehlmann: with puma (the default rails application server) you can spawn multiple workers (== processes), each having multiple threads. so one process can handle more than one request concurrently
[11:09:37] tbuehlmann: not really. if you need that API calls response you have to wait for it. you stated the other option, as in doing it in a background job and use some kind of polling. you have to decide if it's worth the trouble or if waiting might just be okay
[11:38:54] tbuehlmann: you're welcome!
[13:25:41] tbuehlmann: Arkaniad: it this an active record model?
[13:26:14] tbuehlmann: oh, he, actually I meant you
[13:26:32] tbuehlmann: then I suggest not overriding the constructor. you always have access to the models errors by calling .errors on the instance
[13:28:03] tbuehlmann: are these associated models? if so, you can validate them when validating the model itself
[13:28:31] tbuehlmann: they get merge into the instance's errors
[13:39:47] tbuehlmann: that's what I was about to suggest. either that or a lazy loaded instance variable: def model_errors; @model_errors ||= []; end
[13:41:49] tbuehlmann: you're welcome!
[13:42:47] tbuehlmann: alexterziev: what's in app/controllers/sessions_controller.rb:30?
[13:44:40] tbuehlmann: it seems @member is an array and not whatever you think it is
[13:46:43] tbuehlmann: it seems that method returns an array now. I suggest debugging at that point or from a rails console
[13:50:58] tbuehlmann: I get to go now, but it seems you're in good hands with Arkentias. good luck with this
[20:15:22] tbuehlmann: benlieb: can you create a small reproduction script so we can fiddle with it? maybe using this template? https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb
[20:16:56] tbuehlmann: there's also the more active rails slack

2019-01-10

[12:50:34] tbuehlmann: Psy-Q: you could add a catch-all route and respond with whatever you like
[13:11:26] tbuehlmann: Psy-Q: naw, just add a new route as your last route that will catch anything and let a custom controller/action handle it
[16:01:29] tbuehlmann: shouldn't the index include :user_id instead of :user?
[16:07:55] tbuehlmann: shouldn't that be a ping timeout?

2019-01-09

[09:21:56] tbuehlmann: za1b1tsu: up to you really, I think both options are good ones

2019-01-03

[13:32:06] tbuehlmann: Swyper: that's a block you're providing as a method argument. you can run the code from the block in your method by calling `yield`. you can also reference it by having `def function(&block)` and using `block`
[13:38:15] tbuehlmann: well, you wouldn't pass a string as a block, that could easily be a "regular" argument
[13:39:08] tbuehlmann: example: def twice; yield; yield; end; twice { puts('foo') }
[13:40:14] tbuehlmann: if you just want to reverse something, use a regular argument: def reverse(string = 'hello'); string.reverse; end
[16:05:16] tbuehlmann: Ookma-Kyi: did you just posed that question and just pasted a link?
[16:07:07] tbuehlmann: they will probably all work very well, it's up to you and what tech you know/want to learn
[16:16:39] tbuehlmann: I don't know what framework is the best fit as I only know rails very well
[16:18:28] tbuehlmann: people are leaving everything that is not js :)
[16:20:36] tbuehlmann: I don't know the exact requirements and I don't know django and nodejs enough to make a good suggestion
[16:24:36] tbuehlmann: there are by far more php developers than rails developers, I assume
[16:25:04] tbuehlmann: (comparing a language with a framework here, but you'll get what I mean)
[19:14:00] tbuehlmann: orbyt_: for filtering or what's the usecase?
[19:16:06] tbuehlmann: a simple start for that usecase could be a bunch of model scope that you'd just call: Star.with_foo(params[:foo])
[19:16:17] tbuehlmann: handling the presence of the argument in the scope itself
[19:19:40] tbuehlmann: Star.in_main_sequence(params[:whatever]).larger_than_the_sun(params[:whatever]) and so on
[19:19:51] tbuehlmann: they are chainable as a scope should always return a relation
[19:21:42] tbuehlmann: right, that'd be the query param
[19:24:33] tbuehlmann: I don't know the exact usecase. so you can filter on stages? if so, have a ?stage=name-of-stage query param
[19:26:08] tbuehlmann: well, a simple way

2019-01-02

[14:49:02] tbuehlmann: it does not mutate the string but returns a new one. different story for .gsub! which mutates (or returns nil if no changes were made)

2018-12-26

[13:26:59] tbuehlmann: marz_d`ghostman: https://github.com/sinatra/sinatra/blob/v1.4.6/lib/sinatra/base.rb#L1081-L1085 for example
[17:09:30] tbuehlmann: Andr3as: can you paste the code which generates the button? I assume you're using the method incorrectly
[17:14:54] tbuehlmann: you probably just need to use icon('far', 'eye').html_safe
[17:15:34] tbuehlmann: using the block syntax might work as well: <%= button_to new_signal_read_path, remote: true do %><%= icon('far', 'eye') %><% end %>
[17:15:54] tbuehlmann: what exactly does the #icon method do?
[17:16:07] tbuehlmann: it's possible you're concatenating strings and they are not html safe
[17:30:33] tbuehlmann: mh, okay. I always used this: https://github.com/bokmann/font-awesome-rails

2018-12-25

[10:30:47] tbuehlmann: the obvious: /limit: 1,/
[10:40:05] tbuehlmann: do you really want a regexp or do you just care about the number?
[10:41:40] tbuehlmann: this? /limit: \d+,?/
[10:51:26] tbuehlmann: xco: then capture whitespace and commata, too?
[10:56:45] tbuehlmann: I suggest reading up on regexps then

2018-12-22

[08:49:17] tbuehlmann: gambl0r3: have an example of what you mean?
[17:38:39] tbuehlmann: creamme: you might want `link_to(year, meals_path(year: params[:year]))` instead
[19:32:35] tbuehlmann: creamme: it's not usual having such a method in the model. where and how is that defined?
[19:55:19] tbuehlmann: you can put that method in the application controller and add a `helper_method :logged_in?` to that so that the view can use it
[19:56:17] tbuehlmann: see https://api.rubyonrails.org/classes/AbstractController/Helpers/ClassMethods.html#method-i-helper_method

2018-12-19

[10:57:28] tbuehlmann: can you describe what you're actually after? what's the usecase?

2018-12-18

[09:59:45] tbuehlmann: IGnorAND: distinct uses all the columns you're selecting
[10:11:34] tbuehlmann: adac: write a custom validation
[10:17:02] tbuehlmann: adac: you didn't write anything about an inclusion validation, but yes, that's one way to do it
[10:19:05] tbuehlmann: IGnorAND: ordering by (in)valid insurance and using DISTINCT ON should work. you can't use the distinct method for that, though, as that uses DISTINCT and not DISTINCT ON. you'll have to use something like .select('DISTINCT ON (foo) *') (or group, which works similarly)
[10:20:52] tbuehlmann: adac: you want some kind of inclusion validation but for multiple (but not all) values from an array?
[10:23:25] tbuehlmann: write a custom validation then
[13:47:29] tbuehlmann: kidPalooma: rails converts times to UTC when inserting/updating/selecting, so all you times in the database are UTC. now you can setup a default timezone which rails will use for conversions in your config/application.rb: config.time_zone = 'Berlin'
[13:59:12] tbuehlmann: sure, just set the value when creating/updating a record
[13:59:58] tbuehlmann: you should be able to call YourModel.update_all(renewed_at: Time.current)
[14:00:52] tbuehlmann: um, well, I guess you can configure that in mysql?
[14:03:19] tbuehlmann: there are some options it seems: https://stackoverflow.com/a/19069310/384293
[14:03:37] tbuehlmann: connecting with a prepared uri string using serverTimezone=UTC could work as well
[14:06:30] tbuehlmann: I don't think there is one, but you can send raw sql to your database

2018-12-17

[13:12:50] tbuehlmann: that's actually a class method being called
[13:35:11] tbuehlmann: can you gist your controllers?
[13:35:41] tbuehlmann: righty, there's something wrong :)
[13:57:49] tbuehlmann: TvL2386: rails assumes your times are saved using UTC and will convert times to it when querying. you should setup config.time_zone and use Time.current instead of Time.now

2018-12-14

[10:17:04] tbuehlmann: tinyhippo: I'd start by installing things using https://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you
[10:17:21] tbuehlmann: the official guides are great: https://guides.rubyonrails.org/
[10:18:06] tbuehlmann: and then there are quite a lot of guides and intros on the web. the hartl tutorial, for example. never did that, but I read every other day that people like that one
[10:19:44] tbuehlmann: if you're familiar with laravel, that's great. I assume there're lots of similarities
[10:23:42] tbuehlmann: I'd start with chruby, yea. docker just adds complexity you don't need for a start
[10:27:19] tbuehlmann: you're welcome!

2018-12-13

[06:56:15] tbuehlmann: has joined #RubyOnRails
[06:56:20] tbuehlmann: has joined #ruby
[11:21:44] tbuehlmann: hightower2, should be this: https://github.com/rails/rails/blob/v5.2.2/actionpack/lib/action_dispatch/routing/route_set.rb#L319-L334
[13:26:20] tbuehlmann: ActionDispatch::Http::UploadedFile is an uploaded file, so it's working. it just doesn't have a bytesize method to respond to

2018-12-12

[22:29:28] tbuehlmann: Ping timeout: 250 seconds

2018-12-11

[08:25:06] tbuehlmann: what does your staging database has to do with production?
[08:44:48] tbuehlmann: just create the new database and load the old one using psql
[13:30:52] tbuehlmann: I prefer pry over irb

2018-12-10

[09:21:46] tbuehlmann: xco: rails does it for you. what are you after exactly?
[09:23:16] tbuehlmann: the Gemfile.lock lists the dependencies that might be loaded
[11:24:35] tbuehlmann: it really isn't that much of a difference. more secure, if any, is using rails credentials

2018-12-09

[09:36:14] tbuehlmann: adac: that is certainly possible

2018-12-05

[08:25:56] tbuehlmann: dionysus69: same app (controllers, models, …) but without some gems?
[08:41:49] tbuehlmann: you could play with bundler groups and only require certain gems when needed. `Bundler.require(*Rails.groups)` in config/application.rb is a starting point for that
[08:43:01] tbuehlmann: also estimate the time (money) you're wasting doing this vs just upgrading to a bigger dyno
[08:43:51] tbuehlmann: sounds like a new application to me
[08:45:47] tbuehlmann: I assume just using a bigger dyno is way cheaper than your "optimizations" costs, but well
[08:48:33] tbuehlmann: spending hours into this is unviable to the company as well then?
[08:49:01] tbuehlmann: I'd do the maths once to check if this is worth the trouble

2018-12-04

[08:04:33] tbuehlmann: that also applies to passwords, and you shouldn't use simple password as a consequence of that fact

2018-12-01

[11:28:20] tbuehlmann: dionysus69: doesn't sound like a model validation to me then
[12:07:45] tbuehlmann: gavit: have you tried it?
[12:10:10] tbuehlmann: I'd think so, as db:reset does db:drop and db:setup, where db:setup does db:create, db:schema:load and db:seed
[12:10:26] tbuehlmann: you might be after db:migrate:reset
[12:10:33] tbuehlmann: which runs db:drop, db:create and db:migrate
[12:30:03] tbuehlmann: gavit: what exactly do you have?
[12:33:28] tbuehlmann: you probably mean Employment.new(:person => Person.find_by(first_name: "e")) (or Employment.new(person: Person.find_by(first_name: "e")))
[12:37:22] tbuehlmann: remove those spaces

2018-11-29

[10:17:16] tbuehlmann: note that .distinct(:id) doesn't do what you think it does as it's basically the same as just .distinct
[10:18:00] tbuehlmann: I haven't followed in detail and don't know
[10:20:36] tbuehlmann: .distinct works on all the selected columns (which obviously works when only selecting one column). if one want to distinct on one column while selecting more than one, use DISTINCT ON in a select clause
[12:04:40] tbuehlmann: DaniG2k: what's the problem exactly? what have you tried?
[12:07:59] tbuehlmann: why not simply name it @resource?
[12:11:15] tbuehlmann: I thought of @resource ||= organization.lalala
[12:12:30] tbuehlmann: you could also have a inherited class method that gets called when the base controller is being inherited from, then defining the reader and adding the helper method. but to be honest, this doesn't seem like a good idea to me. it greatly complicates the code, making it harder to read
[12:13:09] tbuehlmann: you could also just define the set_<audit-type> in each controller (I assume there won't be hundreds of them) and it'd be easy enough
[12:13:52] tbuehlmann: there's also https://github.com/hashrocket/decent_exposure that came to mind, but I never used it
[12:14:59] tbuehlmann: as said, you can do that in an inherited class method
[12:15:13] tbuehlmann: I'll give you an example
[12:28:45] tbuehlmann: DaniG2k: something like this: https://gist.github.com/tbuehlmann/edbcea1f4719cf0d28b236e3d1b372af
[12:29:40] tbuehlmann: but again, I guess I wouldn't do it. this makes things harder to reason about. and if you really want that, decent_exposure might just do that
[12:30:43] tbuehlmann: you might also need to call `super` in self.inherited, btw
[12:40:32] tbuehlmann: instead of having a base controller you could also have a module doing the same thing, whatever you like

2018-11-28

[17:21:54] tbuehlmann: havenwood: nice!

2018-11-27

[16:03:14] tbuehlmann: adgtl, see: https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs
[16:14:34] tbuehlmann: that's from activesupport and there's no such pendant in ruby
[16:15:18] tbuehlmann: do you mean activerecord?
[16:16:18] tbuehlmann: you can use that without using rails, if that's what you mean
[16:32:33] tbuehlmann: adgtl: that also works for minitest
[16:32:51] tbuehlmann: https://github.com/plataformatec/devise/blob/v4.5.0/lib/devise/test/controller_helpers.rb
[16:36:07] tbuehlmann: have you tried it?
[16:54:58] tbuehlmann: `as` is not for that
[16:57:54] tbuehlmann: ah, you intend to use that backdoor thing?
[17:11:06] tbuehlmann: adgtl: try including Warden::Test::Helpers and running `login_as create(:user)`
[17:12:51] tbuehlmann: login_as works for me ¯\_(ツ)_/¯
[17:15:52] tbuehlmann: ah, there's also Devise::Test::IntegrationHelpers
[17:15:58] tbuehlmann: include that and use sign_in, works for me as well
[17:16:34] tbuehlmann: that is using Warden::Test::Helpers internally
[17:21:20] tbuehlmann: looks good to me
[17:22:08] tbuehlmann: what's in your controller?
[17:25:51] tbuehlmann: are you certain you saved the pads_controller_test.rb file? just to be sure
[17:28:25] tbuehlmann: no idea then

2018-11-25

[17:15:57] tbuehlmann: I often recommend https://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you

2018-11-23

[14:42:50] tbuehlmann: you're welcome!
[16:41:02] tbuehlmann: emers2n: there's no built-in method to do that using js. so, yeah, you'll need to roll your own
[16:41:21] tbuehlmann: adgtl: you want `belongs_to :user, optional: true`