#RubyOnRails - 03 April 2016
« Back 1 day Forward 1 day »
[00:03:15] smathy: Adding it to params won't get it back to your action unless you're doing something special in your form.
[00:03:30] smathy: Just remember, if you put it in the form, then the user can change it if they want to.
[00:04:00] SteenJobs: smathy: ya - so i will get it back - in the update helper, i’d pass the params value as an argument and then update will be able to access it
[00:04:12] SteenJobs: and yea, if the user changes it, authorization will be in place to prevent them from updating other people’s projects
[00:04:27] SteenJobs: but i can’t really think of another way to get the id of the created object to the update action
[00:06:30] SteenJobs: is the extra data stored in session negligible for the most part in terms of slowing things down? like should i be super careful to remove stale or unecessary data from session when it’s no longer needed?
[00:27:16] smathy: SteenJobs, if you're storing the session in the cookie, as is the default, then there's a size limit you want to be conscious of.
[06:09:01] matt_d: trifling-jest: when you say 'current branch,' i'm assuming zsh with oh-my-zsh? :)
[06:11:08] trifling-jest: https://www.learnenough.com/git-tutorial#sec-prompt_branches_and_tab_completion
[06:11:29] trifling-jest: i followed the instructions there then it disable my colored prompt in the terminal
[06:17:50] matt_d: trifling-jest: it appears you have any color codes in your PS1 variable, if you followed that tutorial
[06:25:14] matt_d: trifling-jest: too much to explain in here. check out: http://www.understudy.net/custom.html#color_prompts
[06:25:44] matt_d: trifling-jest: when you look at your .bash_profile, you'll see that you have no color escape codes in your PS1 variable.
[06:29:21] matt_d: trifling-jest: you're just adding "escape codes." think of it kind of like an open html tag setting a color.
[08:53:44] tbuehlmann: hey FooBarWidget, used it for a project some years ago. finding the right apache directives for the ruby version being used and other things wasn't hard, just a bit intimidating because of the long one-page-has-it-all-documentation. it worked for me, but I didn't feel too well with it since I didn't know anything about its implementation and integration with apache. by the time I somehow
[08:53:44] tbuehlmann: switched to thin, then later to puma because they were more, let's say, tangible to me
[08:55:41] tbuehlmann: I also had the feeling that it's a one-person-project (maintained by you) and that it's therefore risky to use it. but that's the case with other web application server, too. so I don't give too much about that argument these days
[08:57:00] FooBarWidget: thanks for the feedback. on the documentation side we've improved that a lot. take a look at www.phusionpassenger.com/library :)
[08:57:45] FooBarWidget: we realized that the one-long-page documentation had reached its limits so we switched to something friendlier. there are now even end-to-end tutorials that cover everything from installing ruby, spinning up digital ocean and deploying rails itself
[08:58:07] FooBarWidget: ironically I'm getting complaints from people who are used to the one-long-page style
[08:58:38] FooBarWidget: they are used to Ctrl-F to search what they need so they now complain that it's *not* one-long-page. I'm trying to reach out to one of those people (I don't know who they are) to see how I can improve the library
[08:59:04] workmad3: FooBarWidget: heh :) that's how I used to find the bits of doc I needed when I used passenger
[08:59:47] FooBarWidget: workmad3: what do you think of it now? I've added various tweaks to accomodate the people who are used to the old style?
[09:00:28] FooBarWidget: tbuehlmann: as for internals, we have lots of internals documentation these days. the entire architecture is documented, how the integration with apache works is documentation
[09:01:09] workmad3: FooBarWidget: I think I'd be happy with the reference listing if I were to use passenger again :)
[09:01:09] FooBarWidget: about 5 years ago it was mostly a one-person-project. nowadays we have more people. we even have a new engineer hire in the pipeline, hopefully for next month
[09:02:31] FooBarWidget: but I'm kind of confused by that. puma and unicorn are *also* one-man projects, so how did they differ?
[09:04:55] tbuehlmann: or do you specifically refer to "these days"? well, I wouldn't know better years ago
[09:06:28] FooBarWidget: passenger has always been a company-backed project, though until 4 years ago the development was effectively one-employee-backed
[09:08:06] tbuehlmann: right, that was a false impression by some-years-ago-me, but that went mistakenly into consideration
[12:05:40] tildes: If I have a controller, that will not render views is it still reasonable to inherit ActionController::Base?
[12:12:10] tildes: tbuehlmann: well, I need something (perhaps a controller), that can have a route, can take in parameters, and respond, most likely with json
[12:12:38] tildes: but it would not have any views of its own, rather, another view would use it (I can get more specific, if helpful)
[12:13:56] tildes: and I was just thinking, rails being quite modular, perhaps I should do something else, than just inherit ActionController::Base, as with my other controllers
[12:14:35] tbuehlmann: still not sure I understand. so it's backed by a route, takes parameters and responds with json? sounds like a typical controller to me
[12:15:14] tildes: tbuehlmann: but it will not have views. ok, if there is no issue really, then I'll just go ahead
[12:16:38] tbuehlmann: you still have to render a result, and that's where the controller comes into play
[13:39:59] JDeen: Hi there. I got a nested form (uses cocoon gem). Wiwht an association like `document has many images`. In `Image` I validate presence of `document`. How ever the create fails as ex: `@document.images.first.document # => nil`. Is this usual behaviour? When handling nested forms how do we validate parent?
[16:17:16] drale2k: what would i use for voice calls via rails like facebook calls or whatsapp calls
[16:37:02] delgiudices: Unique like no other record with same name but not necessarly same exact string
[16:56:31] tbuehlmann: delgiudices, when using postgres, https://github.com/Casecommons/pg_search is an option
[17:03:21] tildes: delgiudices: if you google 'ruby similarity gem' any of the top hits could be something for you
[17:04:10] tildes: also, since there are implementations for correcting spelling mistakes (for instance google's very own 'did you mean...?'), there should be knowledge out there
[17:04:41] tildes: algorithms are not rails / ruby specific, on the gem front you might find something
[17:07:05] tildes: delgiudices: perhaps something like this (http://stackoverflow.com/questions/9822078/ruby-compare-two-strings-similarity-percentage)...
[17:09:48] tildes: (I haven't implemented that kind of stuff myself, but I'm getting the feeling you would like to cache results)
[17:23:13] mwlang: DragonPunch: http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html
[17:26:44] mwlang: DragonPunch: actually, I got to wondering about a more concise listing myself after your question…found a pretty good page here: http://ricostacruz.com/cheatsheets/rails-models.html
[17:31:28] tildes: I have a sketch of a test, a controller in progress, a route and the action in place (the test doesn't assert yet anything) and I get UrlGenerationError, not sure why. What is missing? http://pastie.org/private/txy0mwsn7h0acepu3437g
[17:46:32] P4Titan: so if I have a user with two records: (User x y) and I make both records unique at the DB level
[17:49:57] smathy: "Oh cool, thanks smathy, I'll go google db constraints on multiple columns." "You're welcome P4Titan."
[17:52:41] P4Titan: ai man, I didn't mean anything; sorry. My lapse was because I did search up some stuff
[17:54:29] Limix: Hi all, working on an app that has a feature that syncs all posts with a remote service.
[17:55:23] Limix: what is the correct place to put the actual syncing logic code. I currently have it all in helper files
[17:56:06] Limix: but this is a json api only rails app, and I’m reading that helpers are really for something else entirely
[17:56:12] smathy: Limix, not sure what "helper files" mean, I really hope you don't mean in app/helpers/*_helper.rb modules.
[17:56:21] fryguy: Limix: consider making service objects, or putting the logic in the worker classes themselves
[17:57:08] smathy: Limix, just make a class, put it in app/whatever-you-want can even just be in app/jobs
[17:59:15] Limix: is it good practice to created nested directories inside the integration test folder?
[18:04:32] pikos: hi! we're working on an application to manage ubuntu systems and I'm having troubles with testing our API. Anyone got an idea? Documented it here: http://pastie.org/private/lin6p7vydapmgujpsjcg
[18:05:02] pikos: I'm not sure how to set up the test for /task/:id/notify - it tells me that no route matches my test call
[18:13:12] pikos: smathy: dang, you're right. of course it'd need an ID. Weird that this means that it can't find the route, though. Do you by any chance know the syntax on how to pass the ID or where to look it up? I've been using http://guides.rubyonrails.org/routing.html#listing-existing-routes but it's not very broad
[18:22:23] smathy: piko_, you would usually provide the `:id` in that first argument, along with all your other parameters, but that'd be in a hash for a regular HTML request. Here you're encoding your request body for the JSON request, so I can't think where/how you'd provide the parameters needed for the route.
[18:23:19] smathy: piko_, I would usually test an API with an integration test, where you'd be providing a full string path, and that path would include the ID.
[18:25:14] pikos: smathy: Thanks! I'll try an integration test (like http://guides.rubyonrails.org/testing.html#integration-testing) then
[18:29:59] mwlang: how do I get the name of the activerecord model without all the columns as a string? For example: “Page” instead of “Page(id: …”? I thought it was Page.model_name.name, but #model_name isn’t defined on the AR class.
[18:34:52] mwlang: smathy: just realized I had an instance of the class where I was attempting to get model_name…so… page.class.model_name. d-oh!
[18:40:30] tildes: piko_, smathy: apparently you could provide the path itself in a controller spec, looks a bit strange though http://stackoverflow.com/questions/6665925/get-an-url-or-path-provided-as-string-in-an-rspec-test
[18:40:59] tildes: (just curious about how to do it, wondering what is the best practice in these cases)
[18:43:30] smathy: tildes, not sure how you think that counts as being able to provide the path itself. It's a monkey patch of the underlying method Rails uses.
[18:43:56] tildes: smathy: well, for sure I didn't think very far with it. just curious about how it's to be done
[18:44:42] smathy: tildes, as I said (and as that first answer says), best to just switch to an integration test (or "request spec" in rspec parlance).
[19:45:59] arup_r: Why this error is coming https://gist.github.com/aruprakshit/08595bfd7e5106bdeed72d53b289a0d0 ?
[19:57:29] arup_r: I can use aggregate function one 1 column inside a select.. without group by right?
[19:59:09] smathy: arup_r, I think you know the answer to that: `SELECT SUM(foo) FROM foos` is obviously valid SQL.
[20:00:03] smathy: arup_r, why do you think the error mentions "answers.id"? Where do you think it got it from?
[20:01:19] P4Titan: smathy: Hi smathy. Is this how I would do that unique accross collumns things I asked about earlier
[20:01:32] smathy: arup_r, ok, yes, maybe SQL engines do something magical with the primary key, so that's one possibility, although that wouldn't explain why `SELECT SUM(foo) FROM foos` works.
[20:02:22] smathy: arup_r, let's begin with what we actually know though, just look at just the error itself, is there any more obvious explanation of why the error mentions answers.id?
[20:03:15] smathy: P4Titan, it's a very handy feature, especially for join tables (as this seems to be).
[20:04:03] smathy: P4Titan, heh, no, it's just a loose term to describe a table that has foreign keys pointing to at least two other tables.
[20:04:20] smathy: P4Titan, it sits between two other tables, kind of "joining" them, hence the name
[20:05:17] arup_r: ok.. Answer.joins(:question).select("SUM(answers.id)") is no error. But Answer.joins(:question).select("SUM(answers.id)").first throws the error.. so magic is in .`first` :)
[20:11:29] arup_r: it is telling *"answers.id" must appear in the GROUP BY clause or be used in an aggregate functionn*
[20:13:36] smathy: ...in fact my question specifically stated that the error mentions answers.id - so repeating that the error is telling you something about answers.id is moronic.
[20:17:59] arup_r: well.. when I am saying .first(1), rails needs something based on it can select the first record for me.. which is by default the id of the relation. smathy am I able to explain it correctly?
[20:18:57] arup_r: this is not a guess.. this is what it is doing.. may be I am not able to explain it correctly.. But I got it now. :)
[20:33:15] P4Titan: Hello all. I have a unique validation in a Model as well as in its column. The validation throws one type of error while the database another. Is there a uniform/good way to catch both?
[20:55:23] smathy: P4Titan, because the DB constraint/exception is just protecting you against a very rare, very unlikely race condition, then you can usually just let it 500.
[20:56:20] smathy: P4Titan, if you really want to then put a rescue_from in your ApplicationController and just redirect_to :back, alert: "Temporary internal problem, please try again"
[21:34:19] StevenXL: I have a quick question. Are ActiveRecord callbacks an example of the Observer pattern?
[21:34:50] StevenXL: (I know that there is an ActiveRecord::Observer class, but I'm interested in the callbacks themselves).
[21:47:03] smathy: stevenxl, are you asking if it's implemented using observers? It can be, by providing an instance of an object that is called out to. The inline or own-method version isn't really using an observer pattern. The whole sequence of the saves and callback calls are a kind of Strategy pattern. Not sure what you're hunting for here, is this an assignment question or something?
[21:50:40] StevenXL: smathy: It's not an assignment question. I've decided that to become a better developer, I need to do more than simply learn how to use a framework's API.
[21:52:35] StevenXL: I like the idea of implementing in two different languages to solidfy the insights.