Activity Graph

Page 1 of 2 | Next »


[00:09:51] gr33nw00d: has joined #RubyOnRails
[00:10:02] gr33nw00d: Hello! I find it annoying when I print out a decimal and it displays this: #<BigDecimal:7ff38c2433f8,'0.1974E4',9(18)>
[00:10:23] gr33nw00d: So I find myself all the time doing `amount.to_f`, instead of `amount`.
[00:10:38] gr33nw00d: Am I missing any shortcut or hint here to prevent this repetition?


[02:54:37] gr33nw00d: has joined #RubyOnRails
[02:55:01] gr33nw00d: Is TEXT preferable to VARCHAR(2000) for a longer string?
[03:12:53] gr33nw00d: It's MySQL and it is frequently accessed. Good idea with the benchmarking, just wondering if there are any best practices
[03:12:55] gr33nw00d: or rules of thumb
[04:40:23] gr33nw00d: Remote host closed the connection


[08:18:59] gr33nw00d: has joined #RubyOnRails
[08:19:12] gr33nw00d: Hi. Has anyone experience MySQL deadlocks with counter_cache?


[19:23:05] gr33nw00d: has joined #RubyOnRails
[19:27:05] gr33nw00d: c in the controller, service, another model, or within one of the models themselves? Thank you for your feedback
[19:27:05] gr33nw00d: Hey guys. I was wondering if anyone has suggested recent articles for best practices relating to functionality that deals with multiple models. I've been looking into observers, the cons of callbacks, and service classes, but most of the material is a bit old. For example I have a Flight, Passenger, and Order class and when an order is complete I want to create a flight and assign passengers to it. Is it best practice to put this logi
[19:30:43] gr33nw00d: Read error: No route to host


[06:52:41] gr33nw00d: has joined #RubyOnRails
[06:53:18] gr33nw00d: Are there any gems that help with parameter parsing, ie. say I want my API to include filters like GET /sales?start_date=$gt:2017-01-01


[01:00:50] gr33nw00d: has joined #RubyOnRails
[01:01:38] gr33nw00d: Hey guys. I'm planning to sell tickets for events on a site I'm building. We'll be using Stripe. I was wondering - is ActiveMerchant still the recommended gem for payments? In 2017 is there anything better? I'm either going to use that, or just stripe directly.
[01:01:41] gr33nw00d: Thanks for any input!
[01:44:48] gr33nw00d: Remote host closed the connection


[06:18:21] gr33nw00d: has joined #RubyOnRails
[06:18:28] gr33nw00d: How do I pass my concern a config that can be unique on a per-model basis?
[06:36:00] gr33nw00d: Remote host closed the connection
[14:37:07] gr33nw00d: has joined #RubyOnRails
[14:37:33] gr33nw00d: Are there any recommended gems for reducing boilerplate when enabling query parameters for filtering endpoints on a Rails 5 API?


[03:52:15] gr33nw00d: has joined #RubyOnRails
[03:53:08] gr33nw00d: Hey guys. If I do `belongs_to :some_model, optional: true` it allows me to put bogus values in there, ie. an id of 0. Is there a convenient way to validate the existence of the association if it's present and still be optional?
[04:03:17] gr33nw00d: Good point. I've re-thought this
[04:03:22] gr33nw00d: I think 0 is an acceptable value
[04:03:24] gr33nw00d: as it computes to nil
[04:03:28] gr33nw00d: thanks for your input fryguy



[22:56:13] gr33nw00d: has joined #RubyOnRails
[22:56:31] gr33nw00d: Hello! Within a method, should I default to using @my_var or just my_var.
[22:56:55] gr33nw00d: In many cases the end result is the same. What is the code guideline/best practice for using instance vs regular variables?
[23:05:53] gr33nw00d: I found something similar @Skull0Inc - I will default to the smallest scope that works (local) and use instance vars when needed
[23:06:55] gr33nw00d: I'm pretty confident that we are correct, after some reading :)
[23:08:30] gr33nw00d: a few years haha
[23:08:46] gr33nw00d: How about you?
[23:10:10] gr33nw00d: pundit is awesome
[23:10:26] gr33nw00d: Yep. @user is shared between methods, therefore use instance vars
[23:10:36] gr33nw00d: but if you don't need the value to be shared between methods you should use a local var
[23:13:21] gr33nw00d: Pundit_user eh... weird
[23:13:48] gr33nw00d: My application_policy.rb provides access to current_user via the initialize(user, record) method
[23:14:26] gr33nw00d:
[23:14:31] gr33nw00d: Check this out ^^
[23:14:59] gr33nw00d: Then in all the sub-policies you can just use @user (referring to the current user)


[17:54:09] gr33nw00d: has joined #RubyOnRails
[17:55:35] gr33nw00d: Hello friends! In the guides it states "The Active Record way claims that intelligence belongs in your models, not in the database" ( However when I run "rails g model Place city:references" the resulting migration adds a db-level foreign key constraint `t.references :city, foreign_key: true`. Does this contradict
[18:02:39] gr33nw00d: Ok thank you.


[15:46:06] gr33nw00d: has joined #RubyOnRails
[15:47:49] gr33nw00d: Hi guys. Is it possible to use strong params in a CREATE to create a resource and a child resource? For example, I'd like to create a "Train Terminal" and a location in one request, like so:
[15:52:51] gr33nw00d: beautiful, I knew there was a better way
[15:52:56] gr33nw00d: thank you tbuehlmann
[16:20:39] gr33nw00d: tbuehlmann - I guess accepts_nested_attributes_for only works for creating? Ie. you can't patch one field on a nested accepts_nested_attributes_for model?
[16:24:44] gr33nw00d: Hmmm, this test is throwing other validation errors, like: "location.state can't be blank".
[16:25:34] gr33nw00d: ignore me. didn't include ID in the strong params :)
[16:28:06] gr33nw00d: This also works: `accepts_nested_attributes_for :location, update_only: true, allow_destroy: true`
[16:53:27] gr33nw00d: Remote host closed the connection


[00:51:47] gr33nw00d: has joined #RubyOnRails
[00:53:12] gr33nw00d: Hello. For rails 5 --api what would you guys recommend for formatting my JSON responses? Currently I'm exploring active_model_serializers and Rabl, but it looks like active_model_serializers is undergoing some changes? What is the rails 5 defacto preference?
[00:59:43] gr33nw00d: Thanks fryguy. jsonapi-rb seems powerful, but at the same time a bit "overkill"
[00:59:46] gr33nw00d: in terms of complexity
[01:00:37] gr33nw00d: Do you find it worth the extra time?


[00:35:52] gr33nw00d: has joined #RubyOnRails
[00:36:24] gr33nw00d: In rails 5 if I'm using rspec `rails new myapp -T`, is it possible to change the `rails test` command so it executes `bundle exec rspec` ?
[00:38:04] gr33nw00d: Remote host closed the connection
[02:57:55] gr33nw00d: has joined #RubyOnRails
[16:29:53] gr33nw00d: has joined #RubyOnRails
[16:29:59] gr33nw00d: How can I replace the test command in rails 5
[16:30:07] gr33nw00d: i9u8ygtfdrsza`11se56rdxfgy789jn mklp[]\
[16:31:25] gr33nw00d: Darn, I was really hoping to run my rspec tests with `rails test`


[02:47:45] gr33nw00d: has joined #RubyOnRails
[02:48:00] gr33nw00d: Hey guys, for the life of me I can't figure out how to disable test unit generators
[02:48:08] gr33nw00d: In rails 5.1
[02:50:46] gr33nw00d: Yes, actually I won't be writing any tests for this project
[02:50:52] gr33nw00d: or if I do I'll add them myself
[02:52:30] gr33nw00d:
[03:05:50] gr33nw00d: Remote host closed the connection


[03:45:02] gr33nw00d: has joined #RubyOnRails
[03:46:41] gr33nw00d: Hey guys. I'm using rails 5 in api mode. Usually I'd expect resource :users to create named routes. But `rails routes` doesn't have the names I'm expecting.
[03:46:49] gr33nw00d: Is this disabled in api mode?
[03:47:37] gr33nw00d: Creating a gist.
[03:48:50] gr33nw00d:
[03:51:41] gr33nw00d: @sevenseacat, yes you're right. I'm not sure why I'd expect it to be different hehe. Sorry
[03:53:11] gr33nw00d: Actually, I'd expect to be able to do something like expense_url(1)
[03:54:06] gr33nw00d: Ahh, I was using post.


[07:14:36] gr33nw00d: has joined #RubyOnRails
[07:16:08] gr33nw00d: Hi guys. I'm creating what in PHP I would have called a "library", this is some related functionality. For example, a custom notifier class than handles sending out emails, text messages, etc. Is the best practice to put this code in app/models, lib, or somewhere else?
[07:28:15] gr33nw00d: Hmmm. Thanks very much for the responses. I'm now thinking that this libraries are too application-specific to consider sharing them outside of this project, however they don't deal with any DB stuff.
[07:28:31] gr33nw00d: I guess the lib folder would be my best bet
[07:29:07] gr33nw00d: awesome, cheers
[07:29:30] gr33nw00d: if I add a class to lib/xx.rb, will rails auto load it and it will be available globally?
[07:30:42] gr33nw00d: you include it
[07:31:45] gr33nw00d: Have you guys seen strange errors like this: "A copy of XXX has been removed from the module tree but is still active!"? I think it's due to me using models/libraries in a novice way.
[07:33:02] gr33nw00d: In development only
[07:33:04] gr33nw00d: good thinking
[07:34:58] gr33nw00d: What sort of code would cause an issue like that?
[07:35:23] gr33nw00d: Interesting
[07:36:31] gr33nw00d: It's a wise one
[07:47:58] gr33nw00d: What's your code paste bin of choice?
[07:51:01] gr33nw00d: Here is an example that triggers the "removed from the module tree" error:
[07:52:43] gr33nw00d: It is actually a missing constant haha
[07:53:09] gr33nw00d: Without the actionmailer I get the expected error: "NameError: uninitialized constant"
[07:53:51] gr33nw00d: Yes it seems that way...
[07:54:04] gr33nw00d: sure I'd love to, give me a moment
[07:56:40] gr33nw00d: Here is my team model: (the notify_admin_of_registration lifecycle callback is what triggers the error).
[07:57:19] gr33nw00d: dev_mailer.rb:
[07:58:10] gr33nw00d: Oh sorry that's a good idea.
[07:59:30] gr33nw00d: This gist is updated:
[08:00:15] gr33nw00d: I think I'm doing something wrong with my SlackNotifier class, as it seems to be the constant that causes the error after disabling pieces of code. It still causes the error if I move it to /lib
[08:01:15] gr33nw00d: Error is at the top.
[08:01:38] gr33nw00d: This is run using `rails console`
[08:02:05] gr33nw00d: shoot ignore that error
[08:02:19] gr33nw00d: sorry that's the wrong copy pasta
[08:03:01] gr33nw00d: How embarrasing
[08:03:04] gr33nw00d: Updated ! :)
[08:03:38] gr33nw00d: So that's the error that I expect - "uninitialized constant", however "A copy of Team has been removed from the module tree but is still active!" is unexpected.
[08:05:57] gr33nw00d: Interestingly if I disable the dev_mailer, it works
[08:08:26] gr33nw00d: Derp. Ok one moment will add them instead of putting them all in one file.
[08:08:43] gr33nw00d: Interesting breakthrough. Removing .deliver_later also fixes the bug
[08:11:17] gr33nw00d: prevents, rather
[08:11:38] gr33nw00d: the gists have been updated with sane use of files
[08:12:27] gr33nw00d: My ignorant theory, is that deliver_later is keeping a reference to the Team model, passed to it via self keyword, and then some sort of rails reload magic is happening before the deliver_later queue is processed?
[08:15:11] gr33nw00d: that is a great idea
[08:16:02] gr33nw00d: damn, does not prevent the bug
[08:19:46] gr33nw00d: However something weird is that SlackNotifier is in app/models/services/slack_notifier.rb
[08:21:18] gr33nw00d: I removed spring and the bug was avoided
[08:23:25] gr33nw00d: Yes without spring it works
[08:23:29] gr33nw00d: wow thanks guys
[08:23:51] gr33nw00d: Is spring what prevents you from having to restart your server after making changes?
[08:24:07] gr33nw00d: I always disable turbolinks
[08:24:14] gr33nw00d: now I will avoid spring too haha
[08:24:20] gr33nw00d: I can read the docs on what it does
[08:24:25] gr33nw00d: much love! thanks for your help
[08:24:28] gr33nw00d: this woulda taken me for ever
[08:26:35] gr33nw00d: Ok will do!
[08:27:08] gr33nw00d: At first it felt inefficient, but I can see how there are benefits
[08:27:12] gr33nw00d: ie. if record is updated before job runs
[08:45:04] gr33nw00d: Remote host closed the connection
[16:31:11] gr33nw00d: has joined #RubyOnRails
[16:31:35] gr33nw00d: Client Quit


[21:09:07] gr33nw00d: has joined #RubyOnRails
[21:09:31] gr33nw00d: Hello again. I'm having trouble with rails autoloading picking up my classes in app/services and app/lib
[21:10:10] gr33nw00d: on first boot in a dev environment things work as expected, but after making a change and rails hot-reloading, the Classes I've defined are not found and I get a "uninitialized constant" error
[21:11:22] gr33nw00d: THis is what I'm trying: config.autoload_paths << Rails.root.join('app/lib')
[21:11:27] gr33nw00d: I'll checkout the reading. cheers
[21:12:51] gr33nw00d: Hmmm, it seems that the 2 classes in my app/services folder are not being consistently loaded by rails. I thought the solution is to add them to the autoload path
[21:15:44] gr33nw00d: matthewd - Let me try again. In rails 5 what is the preferred method of adding your own custom classes or services?
[21:18:10] gr33nw00d: matthewd thank you


[01:16:57] gr33nw00d: has joined #RubyOnRails
[01:32:28] gr33nw00d: Remote host closed the connection
[06:25:42] gr33nw00d: has joined #RubyOnRails
[06:26:46] gr33nw00d: Guys, I'm having very unpredictable email sending success with deliver_later on my dev machine using Rails 5
[06:27:11] gr33nw00d: I'm sending email in a loop to 2 users. Often times both emails will be sent, other times and more often only 1 is sent
[06:27:20] gr33nw00d: is deliver_later reliable in development env?
[06:29:10] gr33nw00d: Sorry about that folks
[06:29:22] gr33nw00d: I'll try and watch that - bad habit
[06:30:18] gr33nw00d: I'm using mailcatcher with smtp on localhost:2025
[06:30:24] gr33nw00d: One moment, pastebin incoming
[06:30:46] gr33nw00d: Here's my NotifcationService
[06:30:47] gr33nw00d:
[06:30:57] gr33nw00d: Oh god, strike 2 -.-
[06:31:31] gr33nw00d: Here is the pastie ->
[06:32:08] gr33nw00d: I was going to put something in it but decided not to
[06:32:35] gr33nw00d: Just left it there, thinking that it's inert. The method in question is match_schedule_changed()
[06:33:41] gr33nw00d: This loop creates 2 Notifications. here is the notification.rb model ->
[06:34:19] gr33nw00d: And finally, the NotificationMailer ->
[06:35:01] gr33nw00d: So in my database, consistently, both new Notifications are being created as expected, however seemingly randomly either 1, 2, or 0 emails will be set
[06:42:23] gr33nw00d: @matthewd hmmm, so the first time I run it. It logs and runs both times, but the subsequent times it only runs once
[06:42:49] gr33nw00d: matthewd I have not configured ActiveJob, it is using the default adapter, whatever that is. I'm on rails 5.0 RC1
[06:43:49] gr33nw00d: there are 4 rows, and 3 emails
[06:45:42] gr33nw00d: <- as you can see, there is 1 email in mailcatcher, and the log appears once, however the database has 2 new rows
[06:47:09] gr33nw00d: send_email_notification is triggered 2x as expected
[06:47:11] gr33nw00d:
[06:48:48] gr33nw00d: Hmmm, yes it seems that this behaviour is consistent at least
[06:49:08] gr33nw00d: NotificationMailer.new_notification(self).deliver_later is being called twice, but it only runs once
[06:49:17] gr33nw00d: I know, this is honestly the most confusing bug of this project for me
[06:56:00] gr33nw00d: @matthewd :inline queue adapter fixes the issue, so does using .deliver_now
[06:56:36] gr33nw00d: My curiosity is not satisfied though! Does rails support queues out of the box in a development environment, or do I need to use a queue adapter?
[07:03:08] gr33nw00d: arup_r I'm not sure - it's being unpredictable and not completing jobs
[07:03:23] gr33nw00d: I would be happy with async but it's not working as expected
[07:05:16] gr33nw00d: is it possible to look into the inner workings of async queue, ie. to see the jobs?
[07:19:24] gr33nw00d: I think I'll switch to delayed_job
[07:19:55] gr33nw00d: the default: async
[07:21:15] gr33nw00d: radar - the use case is super minimal, just sending async email
[07:21:25] gr33nw00d: I'd prefer not to have to setup redis or complicate my dev environment
[07:22:13] gr33nw00d: I have starred sidekiq. Thank you for your suggestion
[07:22:27] gr33nw00d: and matthewd, thank you as well for your help
[07:28:53] gr33nw00d: Hmm, yep delayed_job fixed it...
[07:29:16] gr33nw00d: i'm testing with rails console and seeing how many db entries and how many emails with 50.times {|n| Notification.create({user_id: 1, title: 'test', url: '' }) }
[08:38:39] gr33nw00d: Remote host closed the connection


[00:20:46] gr33nw00d: has joined #RubyOnRails
[00:21:23] gr33nw00d: hey guys, question from a noob: how can I update a model but use the pre-updated version in my view? the example is notifications - I want to mark them read after rendering the view
[00:24:32] gr33nw00d: nevermind figured it out
[00:24:34] gr33nw00d: after_action
[01:51:05] gr33nw00d: Remote host closed the connection


[03:11:58] gr33nw00d: has joined #RubyOnRails
[03:28:21] gr33nw00d: Remote host closed the connection


[10:36:41] gr33nw00d: what's the best practice for adding dynamic route constraints based off of current_user (Devise). I'm new to rails and I've been searching for this for a while. Ideally I'd have completely different routes and views based on a user's role. The config/routes seems like the best place for this. Any advice is appreciated. Thanks!
[10:41:32] gr33nw00d: @rushed thanks! I'll do some reading before bed
[11:22:49] gr33nw00d: what's the difference between @my_variable and self.my_variable in a class?


[11:10:41] gr33nw00d: hi guys. in my application there are separate organizations, the current organization effects nearly all of the queries in my app, so I was going to add a where clause to the default query. my application controller identifies the current organization "before_action :get_organization"
[11:11:18] gr33nw00d: what's the best practice for me to make this object accessible in my models
[11:11:46] gr33nw00d: so that I can do something like default_scope { where('organization_id = ?', }
[11:12:41] gr33nw00d: @rushed cool. thank you
[11:12:59] gr33nw00d: my best guess so far was to create a module to store this data


[06:45:46] gr33nw00d:
[06:46:34] gr33nw00d: sorry I misunderstand what you're asking me. however I think you might have found the solution -the string data type
[06:46:41] gr33nw00d: I'm going to see if that fixes it now
[06:49:28] gr33nw00d: @sevenseacat sorry, I'll do better.