Activity Graph

Page 1 of 2 | Next »


[18:17:53] linguini: Anybody using paper_trail to track changes to associations? The paper_trail README says it is possible with a version_associations table, but it seems to be a feature in the beta releases only..


[22:43:49] linguini: klass.ancestors.include?(MyClass) # is there a better way to do this?
[22:44:55] linguini: apeiros: perfect! Thanks.


[20:54:58] linguini: URI.decode_www_form("&x=y") # works in ruby 2.1, but fails in ruby 1.9
[20:56:23] linguini: Is this a bug in ruby 1.9, or is "&x=y" invalid ?


[00:42:11] linguini: [1, 2, 3].map { |x| x if 2 < x }.select{ |x| x } # is there a ruby idiom for this (that is mapping an operation over an array, and then filtering the result to non-nil values)?
[00:43:14] linguini: apeiros_: Oh, right. Hmm. My example is bad...
[00:43:54] linguini: apeiros_: Sweet. compact is what I want!
[00:44:08] linguini: [1, 2, 3].map { |x| if 2 < x }.select { |x| x } # what I should have written originally
[00:44:32] linguini: [1, 2, 3].map { |x| if 2 < x }.compact # yay
[00:46:46] linguini: apeiros_: Thanks, that's another good option.
[00:51:51] linguini: [:a, :b].select { |x|[x]) if h.has_key?(x) }.compact # one case where compact might be preferable
[00:53:28] linguini: oh yeah, map! Hmm. Yes, I can see the preference for select + map too.
[00:54:09] linguini: Though it moves the has_key? conditional farther from h[x]; shrug.
[00:58:16] linguini: apeiros_: hmm! Interesting idea; that would be a nice way to get rid of the has_key? check...


[01:29:29] linguini: I was mistaken earlier about updated_at:
[01:29:51] linguini: Post.comment_ids = [] # comment.updated_at is updated!
[01:29:59] linguini: Post.comment_ids = [2] # comment.updated_at is not updated


[22:38:58] linguini: post.comments << [comment] # <- sets comment.post_id, but does not touch comment.updated_at ..?
[22:43:10] linguini: When using a has_many association, is there any way to set updated_at on the child object when that child is added?
[22:44:57] linguini: bricker: Right. But in my case though comments can be moved between posts, so comment.created_at != comment.time_when_post_id_is_set
[22:45:55] linguini: Radar: comments.each { |x| x.touch } # do you mena, like this?
[22:46:44] linguini: Radar: Hmm. That's another interesting option. What I was going to do was:
[22:47:26] linguini: comments.each { |x| = post;! } # this, to make sure papertrail also got the changes
[22:48:06] linguini: (in a transaction)
[22:48:36] linguini: touch is an interesting option, as is update_all. I'm not sure how they both interact with papertrail, but I can test. Thanks for the ideas.


[14:39:19] linguini: Is there a way to call the "super" of another method, something like ?
[14:40:37] linguini: apeiros: Yes, perhaps. The problem is that B::f is so big that I wanted to break it down into smaller methods. But when I attempted to do that, calls to super broke.
[14:41:34] linguini: apeiros: Thanks. I'll think about this. I don't really want A.instance_method(:f).bind(self).call ...
[15:28:02] linguini: FWIW, an attempt at avoiding A.instance_method(:f).bind(self).call : -> . :-/ I'm sure there's a better design pattern here I have yet to identify.
[15:40:54] linguini: I can't disagree. :-/
[15:41:21] linguini: Unfortunately, the concrete version is rather long, and full of business-specific terminology, and I suspect harder to understand.
[15:42:44] linguini: I basically want to override a single method for one wonky-ish business case. But wonky business case is so wonky, I want to break it down into multiple methods.
[15:42:57] linguini: Here's another (abstract) attempt that allows me to refactor messy code into another method:


[17:07:20] linguini: Is there a ruby idiom for this:
[17:07:25] linguini: class X; def self.meth() end; def meth() self.class.meth; end; end
[17:12:06] linguini: # a more complete example of the constructs for which I'm seeking idioms


[20:37:56] linguini: How can I redirect the current user to the current url, except with one query parameter modified?
[20:41:00] linguini: params.delete(:foo); redirect_to params # triggers Cannot redirect to a parameter hash!
[20:44:22] linguini: pipework: Are you saying the explanation is, "You can't redirect to the current url with one query parameter modified"?
[20:45:02] linguini: pipework: Oh; how do you redirect to the current url?
[20:45:37] linguini: pipework: I want to remove stuff from the url bar.
[20:51:01] linguini: pipework: Given
[20:52:01] linguini: Is there a railsish way to create a redirect to ?
[20:54:37] linguini: pipework: Another related question: is there a railsish way to create a link to where the code is not vulnerable to XSS?


[21:13:16] linguini: I'm using ruby 2.1 and trying to use byebug; it is barely functional; is there some magic to make it work, or does it just suck on ruby 2.1?
[21:14:59] linguini: By suck, I mean: (byebug) help show # INTERNAL ERROR!!! undefined method `to_sym' for ["show"]:Array
[21:22:28] linguini: MaciejCzyzewski: According to, Ruby 2.1.3 was the "current official release". Is that incorrect?
[21:26:50] linguini: peterhellberg: Ah, thanks. Yes, it certainly looks like bugs in byebug. I was hoping for a more efficient way to debug ruby than puts style debugging...
[21:30:25] linguini: So, are there any good alternatives to byebug? Would I have more luck with it if I downgraded my ruby? Does everybody in ruby just live without a debugger?
[21:35:03] linguini: peterhellberg: rake db:rebuild # does a lot of work, then throws unhandled exception
[21:35:47] linguini: I can solve this without a debugger; it's just slower. I would ideally like to get control when the exception is being raised and poke around to look at things.
[21:36:54] linguini: peterhellberg: No; does it get control when an exception is raised? Or do I need to cause it to be invoked at the right time?
[21:38:12] linguini: peterhellberg: Ah. byebug can do that too (without crashing!)
[21:40:52] linguini: peterhellberg: Yes, that looks useful! Come to think of it, I've used pry-rescue in tests before. Unfortunately, I dislike pry, but maybe I should just get used to it.
[21:44:03] linguini: havenwood: I find it awkward. It has too many commands. It assumes you are working in a terminal. Probably all my own resistance to spending time learning it.


[22:36:58] linguini: I've written a very small gem that has one library file and one ruby script. The ruby script depends on no external gems.
[22:37:41] linguini: bundle exec myscript # is quite slow
[22:38:33] linguini: Is there a kosher way to make my gem's bin/myscript directly executable (thus avoiding a 2 second delay for loading unnecessary gems)? Or am I doing something wrong?
[22:39:45] linguini: spec.executables = "myscript"
[22:40:03] linguini: Should I be doing something other than that?
[22:40:40] linguini: Maybe I should be asking in #bundler..?
[22:41:56] linguini: jhass: Well, I'm not sure how to make bin/myscript "available" for direct execution. I'm not familiar with the gem paradigm.
[22:43:08] linguini: jhass: Sorry if I don't understand, but how would a consumer of my gem use foo?
[22:43:29] linguini: gem install # puts foo in /usr/local/bin ?
[22:45:25] linguini: I see. Thanks for the link. I think I have done as that guide describes.
[22:45:44] linguini: I suppose my real question is $ bundle install # puts foo somewhere?
[22:46:28] linguini: I realize bundler can do different things (system gems vs vendor/ vs ~/).
[22:47:00] linguini: Right! bundle exec will work. But it's so freaking slow.
[22:48:34] linguini: jhass: True; but I thought 'bundle exec' is typically slow (over 2 seconds) in rails projects. But maybe I've only worked with bloated ones...
[22:49:06] linguini: myscript, in any case, needs no other gems...
[22:50:43] linguini: jhass: Ah, good to know. I was testing on an old (2006) laptop running 1.9.3.
[23:00:09] linguini: jhass: Thanks; I'll ask for more details in bundler.


[21:29:10] linguini: I've written a small gem to interpret a _very_ small language. And now I realize I want to interpret the same language in javascript. Are there any [realistic] alternatives to duplicating all the parsing logic in a javascript library?
[21:30:00] linguini: havenwood: I just found Opal a few minutes ago; I haven't read about it (yet).
[21:30:55] linguini: havenwood: Yes.
[21:33:11] linguini: racc/yacc == parser generators?
[21:37:42] linguini: foo = bar = [:a]; foo.clear ; foo + bar
[21:37:55] linguini: foo = bar = [:a]; foo = [] ; foo + bar


[15:28:22] linguini: I want to spawn some processes whose output and exit status I do not care about. What's the best way to do this in ruby?
[15:29:57] linguini: Kernel.fork || Kernel.fork || exec ?
[15:47:42] linguini: To answer my own question: Process.detach(Process.spawn(command))


[19:28:05] linguini: Eroc: Are you sure request.headers always = {} ?
[19:28:28] linguini: Eroc: I notice you are using 'HELLO' and 'Hello'...
[19:41:02] linguini: Eroc: request.header["HTTP_Authentication"] # Try using HTTP_ prefix
[19:41:20] linguini: Er, request.headers, ...
[19:46:53] linguini: Eroc: request.headers["X_TESTING"] = 'foo'; puts request.headers["X_TESTING"] # puts 'foo' for me
[19:47:23] linguini: (from inside ActionController::TestCase method)
[19:51:36] linguini: Eroc: Rails 4.0.3 and no rSpec; pure ActionController::TestCase


[17:47:52] linguini: it = (1..100).each # is there a way to change "100" to "infinity"?
[17:53:39] linguini: Hanmac: Cool; thanks.
[17:59:58] linguini: it.peek - 1 # is there a better way to find the "return value of the previous next"?
[18:01:06] linguini: (other than saved =
[18:02:33] linguini: centrx: Hmm. Thanks. I may just more of it.peek and only use when I know I no longer need the "current integer".


[04:55:48] linguini: I'm puzzled about how create! is supposed to work in a callback.
[04:55:51] linguini:
[04:56:43] linguini:
[04:58:51] linguini: As far as I can tell, if Other.create! is called within an after_create, the exception is caught by the outer object, but the outer object creation is not necessarily rolled back.
[05:03:00] linguini: Radar: Hmm. Same behavior when using
[05:03:49] linguini: Radar: I don't know how to create a gist without a mouse.
[05:04:32] linguini: I've banned the mouse from my desk because of the immense pain it causes me.
[05:06:38] linguini: Radar: Ah, thanks; I'll try that out.
[05:09:01] linguini: Radar:
[05:16:53] linguini: What surprises me is that the assertion on line 10 of question_test.rb always passes, but the assertion on line 12 fails when Answer validation fails.
[05:18:09] linguini: Perhaps it is uncommon to use the after_create callback to create other ActiveRecord objects.
[05:22:58] linguini: Hmm. I could do that I suppose. It just seems slightly more brittle long term. I want the question<->answer pairing to be a strong guarantee.
[05:31:20] linguini: I could move the question<->answer pairing into the controller. I could also fix the after_create callback now that I know create! does not behave as I thought. Thanks for the input; I'll consider both options.
[18:12:08] linguini: If 'raise ActiveRecord::Rollback' in an after_create callback, shouldn't the transaction be rolled back?
[18:12:38] linguini:


[21:00:13] linguini: LC_TIME=en_US ruby -rdate -e 'puts Date.parse("06/01/2014")' # 2014-01-06 :-/


[00:40:59] linguini: I want to understand the namespace lookup rules within controllers and views. Any good articles/diagrams for this?
[00:49:09] linguini: Radar: Thanks. I think my trouble is slightly different.
[00:49:13] linguini: I have a heavily used helper method in app/helpers/application_helper.rb that looks like this: def linkit(object); current_user.can_link? ? link_to, o : ; end
[00:49:55] linguini: I use this method really often, but a few times now, I've hit the problem that "linkit" is not defined in the scope within which it's called.
[00:51:11] linguini: (e.g., from within a lambda)
[00:53:13] linguini: Well, my current error is: undefined method `linkit' for Foo
[00:54:37] linguini: undefined method `alink' for Id:ObjectMember
[00:54:47] linguini: Radar: I may prepare a gist. Hmm.
[01:37:43] linguini: Radar:
[01:39:48] linguini: Radar: Yes, I'm trying to decorate. I want to call Rails's link_to helper. I realize I can do it in the view, but I want to do it in a class (I think...).
[01:40:23] linguini: Radar: Ok, thanks. I'll check out Draper...
[22:23:05] linguini: Order.include(:account).uninclude(:account) # is this possible?
[22:23:20] linguini: Order.includes(:account).unincludes(:account) # er, is this possible?
[22:24:31] linguini: workmad3: Can you unscope includes only (and leave other scopes intact)?
[22:25:04] linguini: ACTION trying!
[22:26:25] linguini: workmad3: It works! Thanks!
[22:28:05] linguini: Sweet. Good to know.


[22:16:38] linguini: Is there some way to dynamically find what file/line, if any, defined a particular method?
[22:17:20] linguini: defined?(foo.mymethod) # like this, but beefier
[22:19:27] linguini: jhass: Sweet! Thanks!
[22:35:27] linguini: If a certain query parameter is present, I want to add it to all links created by link_to. Is this possible without monkey patching url_for?
[23:03:30] linguini: lethjakman: Hmm. I was hoping to avoid wrapping every call to link_to and friends. Hmm.
[23:04:11] linguini: Where can I find out how default_url_options is supposed to be used?
[23:32:59] linguini: Is it possible to search the logs from this channel?
[23:34:41] linguini: rushed: Yes, but I don't see how to search this channel (except painfully inefficiently by clicking "1 day back" over and over.


[18:00:35] linguini: [''.html_safe, ''.html_safe].join(''.html_safe).html_safe? # why is this false?
[18:06:31] linguini: lethjakman: Ah, thanks.


[16:21:00] linguini: I have two models that refer to each other (and both have foreign keys to each other). What's the standard way to create such objects in tandem?
[16:23:06] linguini: tubbo: Hubby.create(:wife => Wife.create(hubby))
[16:23:50] linguini: Chicken.create(:egg => Egg.create(:chicken => Chicken.create ...))) # perhaps more clear ?
[16:25:46] linguini: tubbo: Right; sorry, I'm trying to illustrate the problem.
[16:28:13] linguini: tubbo: What I'm actually doing right now is:
[16:28:24] linguini: after_create :create_other
[16:29:14] linguini: But I suspect there's a better way.
[16:30:14] linguini: Bah; I'll think some more...


[21:36:36] linguini: I want to change the delivery_method for action mailer from within a specific rake task; how can I accomplish this?


[05:12:28] linguini: I find I frequently want to render the same object in one of many formats (e.g. a "brief" version and "full" version). I can put one of these versions in the eponymous partial, but is there a better way?
[05:13:15] linguini: render @foo.brief # maybe?
[05:14:07] linguini: Actually, I think render @foo.brief (where brief names a partial) might be what I want!
[05:14:41] linguini: pipework: Thanks for the reply; I don't have a code snippet handy...
[05:17:27] linguini: pipework: The gist would basically be: <%= render "foo/_in_list_context" %> <%= render "foo/_in_other_context" %> ...
[05:18:33] linguini: hmm, actually, I think those renders are bogus because I didn't pass a variable...
[05:19:55] linguini: <%= render foo.listy %> has the advantage of being short, and allows me to implicitly pass foo to the partial.
[05:20:09] linguini: I'll play with it.
[05:21:49] linguini: Radar: Cool; thanks. I've got to move some code around, but I'll try that..


[22:33:11] linguini: I'd like to render one of several possible partials using a "partial search" (so that I can selectively overwrite some parts of a view, but leave common parts common). Is this possible?
[22:33:44] linguini: s/possible/easy/
[22:36:50] linguini: I'm rendering mails, and several mails are /very similar/ but have a few significant differences. I'm trying to keep it relatively DRY.


[20:26:52] linguini: false) # will before_validation hooks be called?


[01:31:06] linguini: Is there a way to make this a relation rather than an array: Model.scopea + Model.scopeb ?
[01:34:14] linguini: toretore: Model.scopea + Model.scopeb returns the union of the scopes, not the intersection.
[02:28:33] linguini: I'm starting to wish for the good old days of building SQL by hand; I suspect somethings wrong with my brain.
[02:30:26] linguini: I'm currently reverse-engineering Arel just so I can get an "OR" inside an SQL query.
[02:34:16] linguini: centrx: Really? I want to "OR" 2 (or more) scopes dynamically. I'm not sure how to accomplish this.


[23:18:08] linguini: Given a klass, how can I find the "new" route for it?
[23:19:17] linguini: link_to "New #{klass}", :action => :new, :controller => ??
[23:22:48] linguini: jammanbo: Undefined method `new_users_path'
[23:23:13] linguini: (when klass is User)
[23:24:17] linguini: <%= link_to 'it', [:new, :user], title: 'do it!' %> # works...
[23:25:36] linguini: DRY. I have multiple classes that I want to handle uniformly.
[23:26:53] linguini: I suppose I could iterate over controllers rather than classes. Hmm.
[23:28:59] linguini: I am trying to implement 4 "buttons" to create new Active Record objects of different types.
[23:29:17] linguini: I don't want to do: new_class_1_path ... new_class_2_path ... if I don't have to.
[23:30:25] linguini: It seems to me that given the class I want to operate on, and the action I want to call, I should be able to find the path without hardcoding 'action_class_foo_path.'
[23:31:12] linguini: These aren't different user classes. One class is User, one class is Post, one class is Comment, etc.
[23:32:34] linguini: [ User, Post, Comment ].each { |klass| link_to ... }
[23:42:46] linguini: jammanbo: [:new,] # works, but I need to also add a query parameter
[23:49:37] linguini: link_to "New User", new_user_path(:domain_id => # instead of this
[23:49:57] linguini: link_to "New #{}", polymorphic_path(:new, + "?parent_id=#{}" # I want something like this
[23:50:38] linguini: Of course, the second is ugly as hell, probably because I don't know routing url_for/link_to/polymorphic_path well enough.


[21:32:21] linguini: How does ri end up with documentation from proc.c? On my machine, it is removing spaces it shouldn't.
[21:32:56] linguini: $ ri UnboundMethod | grep -o 'it wasobjectified'
[21:32:57] linguini: it wasobjectified


[21:43:27] linguini: True or false: the best way to load all code from lib/*.rb is to explicitly do so in config/initializers/loadlib.rb ?


[01:29:41] linguini: I want to generate a mail using ActionMailer, and I want it to contain the current host (of which there may be several). How do I do this?
[01:42:37] linguini: Radar: Hmm. Unfortunately, that will mean a "host" variable on about 12 methods. Hmm. Maybe that's not so bad.


[23:50:58] linguini: Is it just me or is the "time" [database] type in rails totally broken?


[21:59:47] linguini: Instead of including a boolean column 'is_weirdo' on a model, I'd like to have a table 'weirdos' that simply lists the ids of the rare weirdo model. This would make finding weirdos faster, but I'm not sure how to translate "SELECT * FROM weirdos" into rails. Is this notion anti-rails?
[22:02:57] linguini: workmad3: Model: Person, method: is_ruby_programmer
[22:03:22] linguini: workmad3: Are you saying I should do RubyProgrammer < Person ?
[22:04:16] linguini: workmad3: Hmm. Good point. I guess because I assumed the attribute wouldn't be indexed; although if I indexed it, I would believe it would be the same efficiency.
[22:08:41] linguini: workmad3: I suppose I prefer 100s of tables to fat tables, but maybe I'm backwards.
[23:34:49] linguini: nomnomdeguerre: Rails.logger ?


[20:45:01] linguini: I'm interested in using ; should I stick something in Gemfile or should I just copy the javascript and css?
[20:45:25] linguini: s2013: "the gem"?
[20:46:58] linguini: s2013: Ah, cool! Did you already know it existed in rubygems?
[20:47:26] linguini: s2013: Ah cool; that's what I was wondering. Thanks.
[20:49:40] linguini: Senjai: Ah, thanks for the warning.
[20:50:01] linguini: It'll still probably be way faster than I would, but I suppose I can fork as needed.


[22:08:03] linguini: Has rjs been deprecated?


[22:57:57] linguini: I find I'm wanting to manage many-to-many relationships in my application in several places. E.g. /user/1 and group/1 . What's the best way to handle these associations? Backing each relation with an ActiveRecord based model seems a little heavy-weight...
[22:59:08] linguini: gwillen: Hmm. Thanks. If you use has_and_belongs_to_many, how do you usually end up managing the relationship? That is, in urls, how would a user do: /user/1 add_to /group/1 ?
[22:59:38] linguini: CREATE /user_group/?user=1&group=1 # ?
[23:00:01] linguini: PATCH /user/1?add_group=1 # or this?
[23:00:15] linguini: gwillen: Hmm. Thanks.
[23:00:39] linguini: I wonder if there's a gem to make the UI for managing many-to-many relationships easy...
[23:03:47] linguini: gwillen: Actually, even if your URLS are not RESTful, you must still have manage associations somehow. Right?
[23:05:32] linguini: gwillen: Ah. Interesting. I'll think about that for a bit.


[00:09:42] linguini: implies I should use app/assets/controller.js and either use require_tree (to make all controller javascript global to the app?) or use javascript_include_tag to get the controller.js included.
[00:10:43] linguini: Paradox: Why not has_one :main_name, has_many :names ?
[00:11:23] linguini: Radar: Namespace?
[00:39:51] linguini: It seems to me that Rails prefers all your javascript get precompiled into a single file. True?
[00:40:52] linguini: Radar: Hmm. In my case, some users are "power users" and need more js, but most users are "ordinary" and need significantly less js.
[00:42:25] linguini: Radar: Hmm. Good idea.
[01:13:24] linguini: denysonique: Thanks; I'll take a look.
[01:15:00] linguini: denysonique: Yeah, that makes sense.


[23:53:55] linguini: I would like to add some javascript to a view. In what file should I do this?


[21:45:29] linguini: POST vs PUT: Which should I use if I want to change one bit of state in an already-existing resource?
[21:47:32] linguini: method: patch


[16:58:35] linguini: Is there an easy way to get the return value 'save' would give (ala validation checking) without invoking 'save'?


[00:09:52] linguini: I think I've found an inaccuracy in . Namely:
[00:10:12] linguini: "By default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the :layout => true option."
[00:13:41] linguini: If the documentation and rails disagree, how do I tell which one contains the bug?


[23:21:12] linguini: I want to return a table for a javascript request; I don't want <head>...</head> and similar html headers in the response. How should I do this?
[23:26:11] linguini: fir_ed: Hmm. That sounds strange. FYI, a request for /controller/action/id already returns the html table.
[23:26:23] linguini: Perhaps render_to_string will do what I want..
[23:29:01] linguini: fir_ed: Unfortunately, the respond_to only handles .html.
[23:29:20] linguini: fir_ed: The underlying structure is terrible, but I can't fix that now.
[23:30:13] linguini: fir_ed: Not directly, no.
[23:32:39] linguini: fir_ed: The table is currently in show.html.erb, but I could move it to _hack.html.erb. I'm afraid I don't understand "do a .js call to a .js.erb, render the partial using jquery .replace()"
[23:34:40] linguini: ACTION nods
[23:35:48] linguini: The app currently does a javascript request for the page, then uses jquery to find the table and copies the table row-wise into an already existing table in the browser.
[23:36:01] linguini: It's frightening.
[23:43:24] linguini: fir_ed: Hmm. I don't have a subscription, but your code brings several ideas to mind. In particular, I've not before seen <%= j render("partial") %>
[23:46:00] linguini: fir_ed: Thanks; I'll play with that and see what I get. Do I also need to change "respond_to" so that it handles js?
[23:47:40] linguini: Right. And the $.get('/controller/action:id') call should somehow indicate it wants js, right?


[00:09:13] linguini: Apparently the warnings are triggered by: (1) gem 'rake-remote_task', :require => false, (2) require 'rake/remote_task' in a rake file, and (3) --trace given on the command line .
[00:13:48] linguini: Radar: I'm tempted to debug bundle / rake. Any idea how I could break on whatever code is changing ruby's warning behavior?


[23:38:31] linguini: Radar:
[23:39:27] linguini: Radar: Perhaps because of --trace ?
[23:39:40] linguini: Radar: I get 20,000+ warnings, not just from newrelic, also from activerecord.
[23:40:18] linguini: davidcelis: It gets spit into a mail file, and 20,000 lines of warnings are hard to ignore.
[23:40:42] linguini: Radar: Not that I know of; I simply did: rake --trace task
[23:41:14] linguini: However, I notice that plain old rake (not on a rails project), does not give me the same warnings.
[23:41:49] linguini: So, --trace is not supposed to enable warnings? Hmm...