#RubyOnRails - 01 June 2019
« Back 1 day Forward 1 day »
[07:05:42] snowyrooftops: I recently taught myself to use Rails and started building tiny web applications... it's a breeze to use. I was previously an ASP.NET developer.
[07:08:05] snowyrooftops: Ruby has a really good syntax. The best thing about Ruby (that I've tried so far...) is the optional brackets for function calls. Chaining functions is as simple as Object.func1.func2.func3.func4
[07:09:10] snowyrooftops: And the "!"/"?" suffix is pretty neat. It's a great alternative to by-reference/by-value argument passing with the "&" that other languages use.
[14:18:58] jarr0dsz: hello everyone, im trying to solve a little bit complex routing issue once again and im stuck hope some experts can give me some pointers
[14:19:33] jarr0dsz: for example i have this routes: https://0bin.net/paste/5e7zoRwL+Q1ysHgu#OV7d8qLT4DyB64X-exPaCME5GgKCZ89P4mWg7GbLPuu i need 2 named routes for 2 routes that point to the same controller and method but have optional param
[14:20:21] jarr0dsz: so basically im trying to have multiple routes that all point to the same actions
[14:21:25] jarr0dsz: and if no 'stepx' is provided it should route also the controller requests/step1 is this possible somehow?
[14:24:10] randomuseragain: jarr0dsz: If I'm not mistaken, you might be able to do that by defining custom route. Have you tried that?
[14:24:41] jarr0dsz: how about im doing it like so: https://0bin.net/paste/AT3TieHtBFgTYuaQ#wj+DqiqsVHCWriotvQb9Bz1Xv6QSFUqaOupP0l+I9ng
[14:25:40] jarr0dsz: mistake this one: https://0bin.net/paste/kWdjEg4KT2tAFtiC#kBlHOQ7j+zeSyCF02tbN9hZo+P8ITsLplXR748DF2Z5 ( complete )
[14:26:10] jarr0dsz: this should work for /students/identifier/step1 /students/identifier and /students/step1 and /students
[14:27:11] jarr0dsz: the problem is my controller expects a "step" param and this is not included if i output the params
[14:30:21] jarr0dsz: randomuseragain this is my whole output: https://0bin.net/paste/SjzThlVtgj2sPNlp#wPpC4gOzgLtJtIWK6abusCUZxiS76kpXHNOCK5Dq7er
[14:31:10] jarr0dsz: line 22 in the paste gives me not a value for identifier param but for step instead. (:step) is overruling it
[14:31:43] jarr0dsz: so i think i should find a solution to have both /students/step1 and /students/newyork
[14:32:21] jarr0dsz: the steps are always a defined set of steps, step1,step2,step3, could is somehow find a way to differentiate between a 'step' and something else with the routes #totallyconfused on how to solve this
[14:32:42] jarr0dsz: since ofcourse /students/step is assigned to the :step param since the routes is setup like that
[14:33:46] jarr0dsz: + additional i have to find a way to route each step to the correct step instead of hardcoded #step1 i have now. Each step param would route to #step1 in the controller
[14:40:27] jarr0dsz: randomuseragain something like this ( cleanedup) https://0bin.net/paste/-BC6JbP4053Km0q6#0Kr16-bKNjlw5IfR40Ffym3MOMchkkfw3XQTndlZvi9
[14:40:52] jarr0dsz: so im not even very happy with the controller but found it somewhere online on doing multistep forms
[14:41:25] jarr0dsz: for now my main goal is to first get the routes work, with loading correct step from controller
[14:41:51] randomuseragain: jarr0dsz: I could be wrong but have you tried creating a completely different route instead with different syntax and having a specific action for this?
[14:43:53] jarr0dsz: so default value of step = 'step1' so even if i have no step params applied but only a indentifier param /students/identifier. the step param would be 'step1' thus not overwriting the identifier param?
[14:51:22] jarr0dsz: i think im maybe should move the decision making to the controller instead of inside the routes
[14:58:22] randomuseragain: jarr0dsz: When i see /students/newyork, it looks like you want it to hit the step1 action
[14:59:20] jarr0dsz: so /students/newyork should give me params identifier = new york and step = step1
[14:59:59] jarr0dsz: perhaps this is not possible? no-one in the channel has come across this someday?
[15:13:10] jarr0dsz: ok so i just let the params step for now and in the controller i check the value of it
[15:14:15] notarob0t: Hi everyone, not sure if this is the correct channel for this but I'm having issues deploying a rails app over to heroku. Would anyone be able to point me in the right direction?
[15:18:14] notarob0t: havenwood: So when I run "git push heroku master" I get an oudated yarn lockfile error even after I've deleted it. Here's what that looks like: https://dpaste.de/ukd8
[15:20:36] havenwood: notarob0t: regenerate the Yarnfile.lock and check in into git, then `git push` again
[15:21:44] havenwood: notarob0t: the steps suggested in the error message, with `yarn install` should work. if not, let us know what the new issue is.
[15:30:48] havenwood: notarob0t: sanity check that you've for sure added the yarn.lock to git? it's definately committed?
[15:31:28] havenwood: notarob0t: error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`
[15:32:20] havenwood: i guess that makes sense for prod, but why does it think `yarn.lock` needs updating? because yarn.lock wasn't committed at all or there are actually differences? unsure.
[15:42:16] notarob0t: Oh wait. Just noticed this toward the end of the log: [remote rejected] master -> master (pre-receive hook declined)
[15:56:08] notarob0t: havenwood: I just tried deploying using the heroku dashboard and choosing a github deployment method vs the heroku cli. The build succeeds but does not run the app and I think it's because it needs a procfile. Just not sure exactly how to go about setting that up. My app uses a postgresql db, and I start it up using rails server command
[15:57:06] notarob0t: havenwood: would you happen to know what I should add for a procfile if this is the actual solution?
[16:00:56] havenwood: notarob0t: a Profile doesn't hurt. i usually end up adding one as the app grows anyways, for workers.
[16:08:13] DoctorMonocular: here's my attempt: https://gist.github.com/PeteMichaud/003d7faaedbe4067a9d8e778ecbf5825
[16:09:53] DoctorMonocular: right now I have the homepage loading, but if I try any slug, it just fails as no route matches [get] "/testslug"
[16:17:44] randomuseragain: havenwood: ok cool, I've added this to my procfile "web: rails server -p 3001"
[16:20:27] notarob0t: havenwood: For some reason I'm getting this error on heroku: https://dpaste.de/D3OO
[16:22:48] havenwood: notarob0t: you don't, you just put this in your Procfile, and Heroku automagically sets PORT:
[16:34:16] notarob0t: havenwood: You can refer to your app’s config vars, most usefully $PORT, in the commands you specify.
[16:36:59] havenwood: notarob0t: you can set various env vars, then use them by putting a dollar sign in front. Heroku sets port. You just in your env file write the word: $PORT
[16:37:20] havenwood: notarob0t: literally, the line that goes in your Procfile without modification is: web: rails server -p "$PORT"
[16:39:48] havenwood: notarob0t: afaik, Heroku sets PORT for you - it's one of the predefined environment variables
[16:46:37] GreekFreak: I keep getting Uninitialized constact error for my factory, but for the life of me I can't find out why. I've copied one of my working examples and it still gives me the error. Any help would be appreciated for something that I've missed : https://gist.github.com/tscholiadis/68b95a08851506ba717c07ff0a652561
[16:48:32] notarob0t: havenwood: this rails app acts like an api for the react app. I have it communicating over a specific port. So in my react client section I have a proxy defined https://dpaste.de/dFwY and in rails cors.rb file I've got that defined as https://dpaste.de/j7Jd.
[17:00:26] GreekFreak: I solved the issue by mistake. In the Factory, instead of doing "factory :invite_token, class: 'Bluverve/InviteToken' do" I had to do "factory :invite_token, class: Bluverve::InviteToken do". Ironically, the factory creates it as a string...
[17:13:20] Exuma: I have a DB transaction with a method in it. inside that method it doesnt use a transaction. if that inner method raises, why doesnt the outer transaction roll back the inner changes
[17:36:32] naltun: I'm using Rails 5.2.2. I have two Rails apps in two separate folders (eg. `ls # => dir1/ dir2/`)
[17:37:06] naltun: When I run `rake db:migrate` in `dir2`, a migration file from `dir1` is applied to the `schema.rb` file for `dir2.
[17:37:48] naltun: I even moved dir2 outside of the directory with dir1 and dir2, and migrating still applies the migration file from dir1.
[18:28:33] DoctorMonocular: Exuma: does the internal method catch its own exception? to make a transaction roll back the exception has to hit it, not be caught
[18:54:23] notarob0t: Hi everyone, not sure if this is the correct channel for this. I'm having trouble deploying a rails app with react frontend over to heroku. Not sure exactly what's up but the app doesn't appear and could be a deployment issue.
[18:56:21] notarob0t: It's successfully deployed, but doesn't appear to be running because it won't show up when I visit it
[19:16:20] DoctorMonocular: I'm having trouble creating a custom primary key. I have a psql function called id_generator, and I call it like this: https://gist.github.com/PeteMichaud/c20fe0a16f1c7c2d912eb69282bb4404
[19:49:34] xco: I have a polymorphic association that looks like so: https://gist.github.com/xcobar/fb375cc4f7fbeadefbaf0f1deb95fac0 is it possible to joing these three tables? If so, how?
[19:49:56] xco: Can’t seem to find anything online on joining poymorphic association and not sure if this is possible
[19:57:45] DoctorMonocular: yeah I'm saying I don't know why you have that and suspect you should replace it
[19:58:56] DoctorMonocular: I still don't really understand what you mean by that -- of course you can join any tables, but what are you actually trying to do?
[20:00:33] DoctorMonocular: I didn't actually read this, but a quick google turned up: https://www.calebthompson.io/talks/search/
[20:03:09] xco: i thought that term was for when you’re search only through “text” and not across associated methods
[20:03:52] DoctorMonocular: well, it's related -- full text search CAN be on a single table, it's actually a way of sort of combining columns into a single, internal index column and being able to say "is there text in this similar to the following search string?"" and the thing is that you can set up that search to go across whatever tables you want
[20:05:53] xco: heard and came across “full text search” but never thought it could be what i’m looking for
[20:06:50] DoctorMonocular: yeah it's a little tricky because it sounds like it can only do text columns or whatever
[20:07:13] DoctorMonocular: but actually what's happening is that the values of whatever columns you want are being combined into a single, text-based, search column