« Back to channel list

#RubyOnRails - 21 October 2017

« Back 1 day Forward 1 day »
[00:00:26] duderonomy: has joined #RubyOnRails
[00:01:25] cnk: has joined #RubyOnRails
[00:06:49] newcoder: has joined #RubyOnRails
[00:06:55] newcoder: has left #RubyOnRails: ()
[00:07:40] cagomez: has joined #RubyOnRails
[00:08:44] workmad3: has joined #RubyOnRails
[00:10:15] orbyt_: has joined #RubyOnRails
[00:30:30] bnjmnwl: has left #RubyOnRails: ()
[01:00:37] Technodrome: has joined #RubyOnRails
[01:28:56] Technodrome: has joined #RubyOnRails
[01:37:29] orbyt_: has joined #RubyOnRails
[01:47:51] cgfbee: has joined #RubyOnRails
[02:01:33] bruno-: has joined #RubyOnRails
[02:09:25] workmad3: has joined #RubyOnRails
[02:25:42] kapil___: has joined #RubyOnRails
[03:05:16] bruno-: has joined #RubyOnRails
[03:09:06] Saukk: has joined #RubyOnRails
[03:38:32] DarkBushido: has joined #RubyOnRails
[04:10:01] workmad3: has joined #RubyOnRails
[04:17:36] DarkBushido: has joined #RubyOnRails
[04:27:18] timdotrb: has joined #RubyOnRails
[04:59:19] apparition: has joined #RubyOnRails
[04:59:45] bga57: has joined #RubyOnRails
[05:08:27] timdotrb: has joined #RubyOnRails
[05:19:51] LambdaSource: has joined #RubyOnRails
[05:31:15] timdotrb: Anyone familiar with Highcharts? I’m trying to get the first and last values after changing the zoom to calculate the difference between them and am getting strange values
[06:08:32] xco: has joined #RubyOnRails
[06:10:26] alfiemax: has joined #RubyOnRails
[06:10:33] workmad3: has joined #RubyOnRails
[06:19:40] srinidhi: has joined #RubyOnRails
[06:55:30] moei: has joined #RubyOnRails
[07:03:26] LambdaSource: has joined #RubyOnRails
[07:10:47] newcoder: has joined #RubyOnRails
[07:11:53] newcoder: ruby-2.3 is installed on system, can I install rails-5.1?
[07:26:02] baweaver: Have you tried to yet?
[07:26:30] baweaver: you might start with that
[07:27:30] dionysus69: has joined #RubyOnRails
[07:27:30] quazimodo: has joined #RubyOnRails
[07:30:12] newcoder: has left #RubyOnRails: ()
[07:32:40] conta: has joined #RubyOnRails
[07:37:27] conta: has joined #RubyOnRails
[07:46:05] LambdaSource: has joined #RubyOnRails
[07:55:09] Doldge: has joined #RubyOnRails
[08:11:14] workmad3: has joined #RubyOnRails
[08:11:25] LambdaSource: has joined #RubyOnRails
[08:23:51] sagax: has joined #RubyOnRails
[08:25:07] LambdaSource: has joined #RubyOnRails
[08:31:03] LambdaSource: has joined #RubyOnRails
[08:31:11] ams__: has joined #RubyOnRails
[08:33:36] marr: has joined #RubyOnRails
[08:48:41] quazimodo: has joined #RubyOnRails
[08:49:56] apparition: has joined #RubyOnRails
[08:52:50] conta: has joined #RubyOnRails
[08:55:14] kies: has joined #RubyOnRails
[09:02:12] Technodrome: has joined #RubyOnRails
[09:02:30] Saukk: has joined #RubyOnRails
[09:04:51] lxsameer: has joined #RubyOnRails
[09:18:31] mikecmpbll: has joined #RubyOnRails
[09:20:06] ^mtkd: has joined #RubyOnRails
[09:23:09] nikivi: has joined #RubyOnRails
[09:25:41] mtkd: has joined #RubyOnRails
[09:27:51] nikivi: has joined #RubyOnRails
[09:28:59] LambdaSource: has joined #RubyOnRails
[09:38:56] conta: has joined #RubyOnRails
[09:45:10] LambdaSource: has joined #RubyOnRails
[09:45:35] blackmesa: has joined #RubyOnRails
[09:50:47] FernandoBasso: has joined #RubyOnRails
[10:12:09] arBmind: has joined #RubyOnRails
[11:01:54] irishfromua: has joined #RubyOnRails
[11:12:40] ishahnaz: has joined #RubyOnRails
[11:12:50] soahccc: has joined #RubyOnRails
[11:20:59] daemonwrangler: has joined #RubyOnRails
[11:23:47] erts: has joined #RubyOnRails
[11:24:28] erts: Hi everybody! Beginner question here: I see that, generated by the scaffolding, when a form doesn't pass the validation on submit, it renders the new view through the create controller method. This is fine, it gives me access to the form errors and all the rest, but the URL doesn't change, so if the user refreshes the page they'll get an error or some other result on the browser. I know this is intended, because the user is supposed to just fill the
[11:24:29] erts: form again (correctly) and hit submit, but is there any workaround to protect ourselves from this behaviour? Thanks!
[11:27:43] matthewd: erts: "an error or some other result" sounds like a broken browser. You can redirect back to the form if you like, but you'll have to pass along whatever's needed to reconstruct the validation failure etc.
[11:29:03] erts: matthewd: I was referring that rails gives you an error if you don't have an index method, in my case, if I refresh it takes me to the index when I was meaning to refresh the "new" form
[11:29:34] erts: having an index method there is no error, it's just annoying, if you don't have an index method you would get an error saying that you can't request to that URL using GET
[11:30:26] erts: could you give me a good example to reconstruct the validation failure errors? I've been trying a few things but it's quite messy. For some reason I feel like this is very hacky and there should be another way to solve it
[11:31:35] erts: I guess I'd be happy enough rendering the new view from the create method as usual, but updating the URL in the browser, so the refresh scenario doesn't happen
[11:31:53] erts: but it still doesn't make sense to me.... I must be doing something wrong
[11:34:49] quazimodo: has joined #RubyOnRails
[11:37:11] matthewd: I'm confused about why the refresh is ending up at index
[11:38:20] erts: ok let me clarify
[11:39:12] matthewd: You submit the form, it POSTs to /articles (routes to ArticlesController#create), which shows the validation failure. If you then hit refresh, the browser should resubmit the POST, again routed to #create.
[11:40:05] erts: I must be doing something wrong then, hold on a second
[11:40:42] erts: yeah in my case in this scenario, the browser doesn't resubmit and it takes me to the index action
[11:53:22] tbuehlmann: ah, a crosspost from slack :)
[12:07:54] quazimodo: has joined #RubyOnRails
[12:10:48] BloodyMer: has joined #RubyOnRails
[12:12:27] workmad3: has joined #RubyOnRails
[12:15:18] erts: has joined #RubyOnRails
[12:37:07] BloodyMer: has joined #RubyOnRails
[12:52:43] ferr: has joined #RubyOnRails
[12:53:04] ferr: has left #RubyOnRails: ()
[13:13:00] fmcgeough: has joined #RubyOnRails
[13:13:52] alfiemax: has joined #RubyOnRails
[13:16:06] arBmind: has joined #RubyOnRails
[13:21:03] mikecmpbll: has joined #RubyOnRails
[13:26:32] srinidhi: has joined #RubyOnRails
[13:26:49] quazimodo: has joined #RubyOnRails
[13:35:26] unreal: has joined #RubyOnRails
[13:53:23] alfiemax: has joined #RubyOnRails
[13:57:01] dionysus69: has joined #RubyOnRails
[13:57:43] mtkd: has joined #RubyOnRails
[14:15:17] arBmind: has joined #RubyOnRails
[14:23:52] jphase: has joined #RubyOnRails
[14:26:17] conta2: has joined #RubyOnRails
[14:43:32] arBmind: has joined #RubyOnRails
[14:53:11] DrYockel: has joined #RubyOnRails
[15:01:58] Papierkorb: has joined #RubyOnRails
[15:11:18] ^mtkd: has joined #RubyOnRails
[15:14:41] justrying: has joined #RubyOnRails
[15:28:58] reves3: has joined #RubyOnRails
[15:30:46] Technodrome: has joined #RubyOnRails
[15:34:32] reves3: Hi there, I am new around here. I guess this question has been asked a tousand times, I learnt RoR some years ago and developed an app content managment system for a non-profit organization. Since all around RoR was so new to me, I didnt develop any tests around the app. Now I have a little free time again and I would like to upgrade the app or perhaps create from the beginning. The current version is
[15:34:34] reves3: using Rails 3.2 something, what would you do?
[15:35:15] LambdaSource: has joined #RubyOnRails
[15:36:39] matthewd: reves3: If it's smallish, I think I'd consider recreating it -- possibly copying and adapting parts of the existing implementation in the process
[15:38:52] matthewd: If it's large and complicated, I'd more likely try to add tests to the existing app, then upgrade afterwards -- it's harder to be confident about test coverage when adding them retrospectively, but it avoids a situation where you're working on a new/undeployed app for a long time
[15:39:48] netzfisch: has joined #RubyOnRails
[15:41:33] reves3: so i would say it is a small app, here is the repo https://gitlab.com/reves/CGDV-CMS
[15:42:19] reves3: I have it running and until now we havent had any problem, but i really guess it needs and upgrade
[15:46:48] havenwood: I don't see any code in the Repo? Am I just failing on how to show the code?
[15:47:39] alfiemax: has joined #RubyOnRails
[15:48:31] matthewd: Yeah, I don't see anything either
[15:49:11] reves3: oh, then I have to make it public, I tought it was already
[15:50:56] LambdaSource: has joined #RubyOnRails
[15:52:01] reves3: So now it should be visible
[15:54:09] matthewd: reves3: https://gitlab.com/reves/CGDV-CMS/blob/master/config/initializers/secret_token.rb#L7
[15:54:13] alfiemax_: has joined #RubyOnRails
[15:57:01] reves3: matthewd: oh thanks for that
[15:59:35] Papierkorb: has left #RubyOnRails: ("Konversation terminated!")
[16:00:52] matthewd: The multilingual mixture of names seems like it would be unpleasant to work with
[16:01:16] matthewd: (but I acknowledge that's much easier to say when I've never really had to consider an alternative)
[16:01:45] bruno-: has joined #RubyOnRails
[16:04:20] reves3: Yes the multilingual support is a mess
[16:13:43] workmad3: has joined #RubyOnRails
[16:21:34] matthewd: reves3: So, from a quick read-through, yes I think I would rewrite -- but that partly depends on what you think of the current code quality level
[16:21:52] matthewd: reves3: .. and also how important quality is, I guess: if it's hardly ever touched, maybe it doesn't matter
[16:28:03] reves3: matthewd: Thanks a lot, well I am the only developer and I guess it will continue to be so, so the code is hardly touched. But now and then I try to upgrade it to the latest version of rails, but sometime I have cannot do it that often. So now that I read the code I find it hard to maintain :P So I guess I would rewrite it
[16:29:58] alfiemax: has joined #RubyOnRails
[16:37:18] arBmind: has joined #RubyOnRails
[16:49:56] conta1: has joined #RubyOnRails
[16:50:30] dviola: has joined #RubyOnRails
[17:01:28] Papierkorb: has joined #RubyOnRails
[17:07:17] mcr1: has joined #RubyOnRails
[17:10:38] BloodyMer: has joined #RubyOnRails
[17:21:48] bruno-: has joined #RubyOnRails
[17:34:13] NoGodDamnIdea: has joined #RubyOnRails
[17:48:04] mcr1: has joined #RubyOnRails
[17:53:23] LambdaSource: has joined #RubyOnRails
[17:56:37] Technodrome: has joined #RubyOnRails
[18:07:59] Papierkorb: has left #RubyOnRails: ("Konversation terminated!")
[18:14:13] workmad3: has joined #RubyOnRails
[18:22:42] LateralOctober: has joined #RubyOnRails
[18:27:38] arBmind: has joined #RubyOnRails
[18:43:38] crova: has joined #RubyOnRails
[18:45:44] crova: greetings everyone! I'm trying to store an object extracted from an API call. I'm not sure how to build the controller to store it, my currently code returns me the error found on this gist: https://gist.github.com/crova/95ac81258d1079bbdfffdb3877a0bb3f Anyone up do help a noob out? Cheers
[18:48:13] matthewd: crova: What's your question?
[18:50:45] crova: matthewd, well, a hint on how to save each value of camp_data_name, camp_data_comission and camp_data_subid into the database. What I came up with tells me that I need to pass up a hash as an argument when assigning attributes. I looked into this error but did not manage to make sense of what I found on stackoverflow
[18:51:30] matthewd: What are you currently passing?
[18:51:31] orbyt_: has joined #RubyOnRails
[18:56:07] crova: I isolated the 'names', 'subids' and 'comissions' on different arrays and was trying to iterate through the camp_data_name array to save each value as "camp_name"
[18:58:03] crova: I just put the camp_data_name array on the gist
[18:59:40] matthewd: Okay, different question.. how close do you think the current code is to working?
[19:01:28] crova: far I guess
[19:12:03] Papierkorb: has joined #RubyOnRails
[19:15:36] matthewd: The plucking seems odd to me. The data is arriving with the various values grouped together for each record, but you're flattening that out into a series of disconnected lists.
[19:17:53] crova: I thought it would be easier to isolate them before storing, but finally it didn't help anything (mostly because I'm not sure on how to do it). So I guess I could use the object before all the plucks
[19:18:59] banisterfiend: has joined #RubyOnRails
[19:19:04] matthewd: The digging on lines 6-9 is a bit unclear too
[19:20:46] conta: has joined #RubyOnRails
[19:23:30] crova: matthewd, I updated the gist with the full API response, before the digging, I just wanted to get rid of the "request" and other unnecessary information
[19:24:22] matthewd: More specifically, calling dig with a single argument is weird
[19:24:53] crova: but, It is working with "Ybox.create(:camp_name => x['name'], :camp_total_comission => x['approved_comission'], :camp_subid => x['affiliate_info1'])"
[19:25:52] crova: matthewd, truth is, I will make a lot of weird thing due to lack of basis. I will start to read the well grounded rubyist to get some knowledge on how stuff works and how to build proper code
[19:26:21] crova: so far I just watched a few tutos and started working on something I needed, but if you check my app is a freaking mess
[19:29:24] matthewd: Yep, that's fair enough. TBH this looks surprising to me partly just because dig and pluck are both quite new -- so they aren't what I think of as 'default' approaches
[19:32:55] crova: I stumbled upon those while trying to store another API response to the database when I was starting and I guess it just sticked in my head
[19:56:10] tekk: has joined #RubyOnRails
[19:59:12] mynameisdebian: has joined #RubyOnRails
[20:03:55] mynameisdebian: I am building a database in MySQL that I would possibly like to translate to Rails later. I am reading information here on "Rails-friendly SQL" https://www.tutorialspoint.com/ruby-on-rails/rails-active-records.htm . It says "Given entity x and entity y, if entity y belongs to entity x, then table y has a field called x_id." What does this mean when I have a many-to-many relationship? For example, I have a table "Games"
[20:03:55] mynameisdebian: with a child table "Categories". A category can have many games, and a game can have many categories. So I have an intermediate table, "games_has_categories". The PK field of Games is "id" and the PK field of "Categories" is id. Will the fields in the "games_has_categories" table be called "categories_id" and "games_id"?
[20:05:22] matthewd: mynameisdebian: The default name for the table would be categories_games, and the FKs are category_id and game_id
[20:06:29] mynameisdebian: matthewd: does "categories_games" imply that categories is the child of games?
[20:06:37] matthewd: The x & y in the sentence you quote are misleading too... the table `ys` has a column `x_id`
[20:07:52] blackmesa: has joined #RubyOnRails
[20:08:01] matthewd: No; it's a relationship of equality, so the ordering of the names is arbitrary -- it just has to be consistent when coming from both directions. So the two model names are sorted alphabetically.
[20:08:55] Papierkorb: has left #RubyOnRails: ("Konversation terminated!")
[20:09:08] mynameisdebian: are they always sorted alphabetically?
[20:09:14] mynameisdebian: or is that just a convention?
[20:09:23] matthewd: All of this is convention
[20:09:51] matthewd: If you want Rails to be able to guess the table name, they're sorted alphabetically. If you want to specify the table name manually, you can call it anything you like.
[20:12:02] mynameisdebian: matthewd: BTW, wouldn't the FKs be called "categories_id" and "games_id" (in the plural, as with the original tables)?
[20:12:39] matthewd: As with what now?
[20:12:55] matthewd: categories_id shouldn't appear anywhere
[20:13:14] matthewd: If it's an FK, it'll always be category_id -- it's an integer, so it can only be pointing to one category
[20:13:32] matthewd: If it's the PK of the categories table, it's `id`
[20:14:00] matthewd: (again, by default conventions)
[20:14:23] mynameisdebian: the link I gave says each table should be named in the plural. So if I have two tables named in the plural and I establish a many-to-many relationship between them, won't Rails just insert the underscore? Or are you saying it intelligently reduces "categories" to "category"?
[20:14:40] matthewd: The latter, yes
[20:14:56] workmad3: has joined #RubyOnRails
[20:15:12] arBmind: has joined #RubyOnRails
[20:15:45] mynameisdebian: I just want to clarify, you're saying it's embedded in rails for it to know that "categories" is the plural of "category"?
[20:16:57] mynameisdebian: what if a table were called reveries, would Rails then incorrectly reduce it to "revery" (not a word), or does it have a large dictionary built-in to know the difference?
[20:17:57] matthewd: Just checked.. it gets it wrong. You'd add an exception in your application.
[20:19:49] matthewd: There's a short list of rules that attempt to get decent coverage (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb), then per-application exceptions for anything they miss
[20:20:59] matthewd: Per the comment there, the rules are basically stuck now, even if we realize one is generalizing an exceptional case, or something
[20:22:17] mynameisdebian: I think it's pretty cool, it's just so unusual for a DB of any kind to do something like that
[20:23:27] mynameisdebian: or maybe not, I'm not super-experienced with a lot of DBs
[20:23:37] mynameisdebian: seems very Rubyish though
[20:25:48] matthewd: Yeah, I'd agree with that -- it's doing a more complex thing (with risk that it'll get it wrong), just for a small improvement in cosmetics/ergonomics
[20:26:20] matthewd: I think that's pretty Rubyish, and very Railsish
[20:26:56] mynameisdebian: yeah right, now that I think about it it clearly adds nothing, when they could have just kept the plural name
[20:28:01] matthewd: I think it adds everything
[20:28:56] matthewd: Especially when you move past the actual DB schema, and into the models: you really do want the class to be called Category, not Categories, for example
[20:29:48] matthewd: but then, it's kinda my job to be a Rails-magic-apologist, so... :P
[20:39:54] mynameisdebian: I think because I'm just learning Rails I don't completely understand the benefits
[20:41:38] mtkd: has joined #RubyOnRails
[20:45:42] mynameisdebian: Say I have a table that refers to itself on a single primary key (Games has many other Games). Since I can't have two fields on "game_id" on the join table, is there a default for the names, or do I have to use an exception in Rails?
[20:55:31] mynameisdebian: I guess it was a stupid question, I found a better way to do it
[21:07:41] DTZUZO: has joined #RubyOnRails
[21:07:43] justrying: has joined #RubyOnRails
[21:47:12] banisterfiend: has joined #RubyOnRails
[22:10:20] Skull0Inc: has joined #RubyOnRails
[22:20:33] Nuck: What would you guys suggest for grouping actions to be done at the end of a request or background worker? So, like, if I have to sync a set of updates to an external API and I want to batch them up
[22:21:34] Nuck: So maybe I call `do_thing` 5 times during a request in various after_commit hooks, but I want them to run at the end of the request as some big bulk hit to reduce overhead (there's noticeable lag on each request)
[22:22:18] Nuck: I know Chewy does this for elasticsearch, but I can't figure out quite how it's doing it. I was thinking of using Thread/Fiber-local variables but that seems prone to, uh, *issues*
[22:24:17] Nuck: Sending the batch is easy, I can do it in a controller lifecycle hook or rack middleware, but building the batch seems trickier
[22:25:53] marr: has joined #RubyOnRails
[22:32:43] banisterfiend: has joined #RubyOnRails
[22:34:22] stevednd: I'm getting a load error when trying to require ruby-bitly into my rails app. I get the message `Bitly is not a class` which it's not. It subclasses OpenStruct. It works fine on its own outside of rails. Is there some way to work around this?
[22:41:49] stevednd: nevermind, turns out the the constant was already defined
[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:13] Skull0Inc: gr33nw00d good question! I came across this issue myself. What I realized is that its best to use the @var for allowing the view access to that resource and just keep it as plain var for just use by the controller not meant to be shared
[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:18] Skull0Inc: gr33nw00d: However I'm kinda new myself and would defer to other more knowledgable opinions.
[23:06:55] gr33nw00d: I'm pretty confident that we are correct, after some reading :)
[23:06:59] Skull0Inc: But overall , do what makes most logical sense for good structure.
[23:07:48] Skull0Inc: gr33nw00d how long have you been using Rails?
[23:08:30] gr33nw00d: a few years haha
[23:08:46] gr33nw00d: How about you?
[23:09:38] Skull0Inc: gr33nw00d nice! just about 6 months now. Love it! Just recently learn authentication (custom) / authorization (before actions- custom) and Pundit.
[23:10:10] Skull0Inc: I had that issue with pundit where I didn't know whether to use just var or @var because they have something called @user and @record.
[23:10:10] gr33nw00d: pundit is awesome
[23:10:21] Skull0Inc: Love how the code looks in the end.
[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:11:28] Skull0Inc: they actually have some pre-requisites that require the use of defining a pundit_user methof
[23:11:35] Skull0Inc: thats was the confusing part.
[23:11:57] Skull0Inc: so every time an action is called they reference current_user
[23:12:48] Skull0Inc: made it local vars I think, unless I had to display something from user on the page.
[23:13:21] gr33nw00d: Pundit_user eh... weird
[23:13:31] Skull0Inc: Love how access can be done just like that...took me a few days to 'get it' though.
[23:13:48] gr33nw00d: My application_policy.rb provides access to current_user via the initialize(user, record) method
[23:13:49] Skull0Inc: user = helpers.current_user
[23:14:20] LambdaSource: has joined #RubyOnRails
[23:14:26] gr33nw00d: https://gist.github.com/otang/e93c70e5c15dd17a3913cf502d6dcbcf
[23:14:28] Skull0Inc: So you give access to current user from there?
[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)
[23:15:11] Skull0Inc: I ended up creating a method pundit_user which is called by Pundit, every action for defined controller.
[23:15:15] Skull0Inc: Ok will do.
[23:16:14] Skull0Inc: Ahh, i see how the reoles are done.
[23:16:45] Skull0Inc: The user there is *default* when a new policy is created.
[23:17:14] Skull0Inc: The tricky part was understanding how the two work.
[23:17:27] Skull0Inc: so the record is the passed in paramater.
[23:18:40] Skull0Inc: such as going to users/11/edit. when going there it would call pundit_user set the @user in the policy and check against the passed in record in this case user/11
[23:19:20] kies: has joined #RubyOnRails
[23:19:40] Skull0Inc: Sorry, went off on a tangent there. I just realized that I'd like to contribute to things I can help with.
[23:26:01] Skull0Inc: https://github.com/elabs/pundit#customize-pundit-user
[23:49:49] w0rd-driven: has joined #RubyOnRails
[23:50:30] LambdaSource: has joined #RubyOnRails
[23:55:04] justrying: has joined #RubyOnRails
[23:57:24] DarkBushido: has joined #RubyOnRails