havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.3, 3.0.5, 2.7.7, 3.2.0-rc1: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ | Logs: https://libera.irclog.whitequark.org/ruby/
axisys has joined #ruby
FullMetalStacker has joined #ruby
FullMetalStacker has quit [Client Quit]
hightower2 has joined #ruby
cryptkeeper has quit [Quit: Connection closed for inactivity]
Shortstop has joined #ruby
<Shortstop> Hey there, can someone help me figure out how to create a nested do loop in Ruby?
<Shortstop> This is what I have: https://bpa.st/IZWZM
<Shortstop> When I use 'rails c' rails console, it's telling me that the part right after the params[:searchterm] is invalid syntax
<adam12> Shortstop: Ruby uses two equals for most equality checks.
<adam12> Shortstop: And generally `[]` not `Array.new`
<adam12> Shortstop: You're also missing an `end` for your `if` block.
<adam12> Easy way to tell is the indentation of `end`'s stops abruptly.
<Shortstop> Does that look better? https://bpa.st/VU3LG adam12
<adam12> Shortstop: Yes.
<Shortstop> when I use that in rails console its spazzes out though
<adam12> Shortstop: Explain.
<Shortstop> if I put it as one liner:
<Shortstop> Cookout.all.each do |cookout| cookout.foods.each do |food| if food.name == params[:searchterm] puts food.name end end end
<Shortstop> Output: (byebug):1: syntax error, unexpected `end', expecting end-of-input
<Shortstop> ...erm] puts food.name end end end
<adam12> One liner won't work without semi-colons.
<adam12> Cookout.all.select { |cookout| cookout.foods.any? { |food| food.name == params[:searchterm] } }
<Shortstop> Hold on, before you refactor it
<Shortstop> what would it take to make mine into a one liner with semi colons?
<adam12> Cookout.all.each do |cookout| cookout.foods.each do |food| if food.name == params[:searchterm]; puts food.name end end end
<adam12> Does that work?
<Shortstop> still complains about the first 'end'
<adam12> Shortstop: It "works" here so it must be related to the byebug parser or your Ruby version.
<Shortstop> Hmm
<Shortstop> here's my version:
<Shortstop> Cookout.all.each do |cookout| cookout.foods.each do |food| if food.name === params[:searchterm] matches.push(cookout) end end end
<Shortstop> Rather, I'll try the colon too sorry one sec
finsternis has quit [Read error: Connection reset by peer]
hightower2 has quit [Remote host closed the connection]
Shortstop has quit [Quit: Client closed]
sylario has quit [Quit: Connection closed for inactivity]
caedmon has joined #ruby
caedmon has quit [Ping timeout: 252 seconds]
cartdrige has joined #ruby
cartdrige has quit [Client Quit]
cartdrige has joined #ruby
ur5us has quit [Ping timeout: 260 seconds]
Mikaela has quit [Remote host closed the connection]
Mikaela has joined #ruby
John_Ivan has quit [Remote host closed the connection]
Synthead has joined #ruby
<Synthead> Is this valid yardoc? @param action_at_end [:stop_timer, :repeat_timer, :start_chrono] Action at end of timer.
<Synthead> I want to document explicit symbols
Rounin has quit [Ping timeout: 256 seconds]
shiru has joined #ruby
desnudopenguino has quit [Ping timeout: 260 seconds]
caedmon has joined #ruby
caedmon has quit [Ping timeout: 246 seconds]
caedmon has joined #ruby
caedmon has quit [Ping timeout: 272 seconds]
jhass has quit [Ping timeout: 272 seconds]
jhass has joined #ruby
caedmon has joined #ruby
caedmon has quit [Quit: caedmon]
Mikaela has quit [Ping timeout: 255 seconds]
Mikaela has joined #ruby
shiru has quit [Quit: leaving]
mdemo has joined #ruby
teclator has joined #ruby
tomtmym has joined #ruby
tomtmym has quit [Changing host]
tomtmym has joined #ruby
gr33n7007h has quit [Quit: WeeChat 3.7.1]
gr33n7007h has joined #ruby
swaggboi has quit [Ping timeout: 252 seconds]
swaggboi has joined #ruby
Synthead has quit [Ping timeout: 248 seconds]
reset has quit [Quit: reset]
pusewicz has joined #ruby
pusewicz has quit [Client Quit]
jvalleroy has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
jvalleroy has joined #ruby
crax23 has joined #ruby
Y05hito__ has joined #ruby
cartdrige has quit [Ping timeout: 252 seconds]
crax23 has quit [Ping timeout: 252 seconds]
Pixi` has joined #ruby
_ht has joined #ruby
Pixi has quit [Ping timeout: 272 seconds]
hightower2 has joined #ruby
sylario has joined #ruby
moldorcoder7 has quit [Ping timeout: 255 seconds]
tomtmym has quit [Quit: Gone.]
hightower2 has quit [Remote host closed the connection]
Y05hito__ has quit [Ping timeout: 264 seconds]
FullMetalStacker has joined #ruby
FullMetalStacker has quit [Client Quit]
Sankalp has quit [Ping timeout: 260 seconds]
Sankalp has joined #ruby
c10l has quit [Read error: Connection reset by peer]
c10l5 has joined #ruby
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
Rounin has joined #ruby
Rounin has joined #ruby
Rounin has quit [Changing host]
markong has joined #ruby
FetidToot has quit [Ping timeout: 252 seconds]
FetidToot has joined #ruby
cartdrige has joined #ruby
caedmon has joined #ruby
caedmon has quit [Quit: caedmon]
caedmon has joined #ruby
caedmon has quit [Ping timeout: 246 seconds]
cartdrige has quit [Quit: I am more peaced off than a dragon trying to blow out candles]
<Doc_X> I've got a rake/ActiveRecord migration question (no rails, just rake db migration). I'm using the a gem (`Departure`) to do my mysql DB migrations and I want to pass some configuration to it when the `load_config` step happens.
<Doc_X> I tried to add the config via `config/initializers/departure.rb`, but that is being called on startup by `rake`, then my config is overwritten by the defaults later on. I know I could add something into the migrations, but I know there's gotta be a better way to configure this in a central location.
<Doc_X> I've done a fair bit of googling and SO reading, but everything I see either talks about some rails modification (which isn't applicable for me), or modifying the individual migrations. Any chance someone has a pointer to some config doing this kind of thing I could look at?
cartdrige has joined #ruby
yxhuvud has quit [Remote host closed the connection]
yxhuvud has joined #ruby
John_Ivan has joined #ruby
cartdrige has quit [Ping timeout: 272 seconds]
Mikaela has quit [Remote host closed the connection]
Mikaela has joined #ruby
sam113101 has quit [Ping timeout: 260 seconds]
Synthead has joined #ruby
Shortstop has joined #ruby
<Shortstop> hey there, can someone help me figure out the nested routes I have for my rails application, and how to access 'location' properly?
<Shortstop> Here's my config/routes.rb: https://bpa.st/MSALO
<Shortstop> Here's my frontend function trying to create a location for a specific party, its a React frontend, but its just JS for this part: https://bpa.st/RYHQG
<Shortstop> When I try to create a location via that workflow above, I get this in the Chrome web developer console: AddLocationForm.js:19 POST http://localhost:4000/parties/1/location 404 (Not Found)
<Shortstop> Is it because I should have had 'locations' (plural) instead of 'location' for the nested routes above? I ask this because I really only want a single location for a party though, so I'm a bit confused
<ox1eef_> Shortstop: run 'rake routes' and you will see what it expects.
<Shortstop> Cool, thanks I'll try that
<Shortstop> its a rails project, so I think rails routes would be good too
<ox1eef_> 'rake routes' is a Rails rake task.
<Shortstop> POST /parties/:party_id/location(.:format) locations#creat
<Shortstop> POST /parties/:party_id/location(.:format) locations#create
<Shortstop> Interesting, I thought that's why I'm doing within the fetch request on the frontend though in the same format... weird
cartdrige has joined #ruby
<ox1eef_> I don't see why that's a 404 then, maybe the controller is being hit but the record is not found
___nick___ has joined #ruby
<Shortstop> Durr on my end, I didn't even specify the create function on the 'locations_controller'
<Shortstop> Sorry about that, sometimes its a lot of moving parts. You're right the 'rails s' logs pointed to the fact that the 'create' method didn't even yet exist on the 'locations_controller'
___nick___ has quit [Client Quit]
<Shortstop> Thanks for the heads up on 'rails routes', that made it very simple to figure out what routes I could even use
___nick___ has joined #ruby
<adam12> Doc_X: Show departure.rb in a gist.
<ox1eef_> Shortstop: No worries. I'm glad you figured it out.
entropy has joined #ruby
<adam12> Doc_X: I'm surprised the configuration is being overwritten. How are you observing that?
entropie has quit [Ping timeout: 252 seconds]
entropy is now known as entropie
desnudopenguino has joined #ruby
<Doc_X> I'm seeing stderr being sent to the log file, not redirected to stdout
<Doc_X> er... not sent to stdout
<adam12> Doc_X: What happens if you pass a boolean to that option, not a string?
<adam12> ie. false, not 'false'
<Doc_X> Also, https://gist.github.com/dylan-tock/d67e619d9f0ff4f1311c8ffb1c03e059 . . . lemme try `false` instead of `'false'`...
<caleb> Does anyone know where I could find a copy of the v2 FLTK bindings that used to live at http://rubyforge.org/projects/fltk/ like, a decade ago
<Doc_X> adam12 that works! so simple and yet i overlooked it. thanks!
<adam12> Doc_X: No problem :)
<cartdrige> caleb, if it's not in the gem repository, maybe on github, but it may not work anymore
<adam12> cartdrige: gem fetch/gem unpack?
<cartdrige> like the old QT=ruby bindings not working/maintained anymore.
<adam12> err, & caleb
<caleb> oh I don't expect it to work, I just didn't want to start from scratch on my own bindings
<caleb> no gem
<caleb> I'll ask on mastodon too
<caleb> maybe somebody is an archivist with a copy
<Doc_X> caleb: you could always try the internet archive
<caleb> if you try to browse the tree via the wayback machine from the "Browse the Subversion tree" on this archived page it's bunk https://web.archive.org/web/20140514074725/http://rubyforge.org/scm/?group_id=2779
<caleb> does the internet archive do source?
cartdrige has quit [Ping timeout: 265 seconds]
<Shortstop> I'm having such a hard time figuring out how to really access 'location' as its supposed to be tied to the 'party' in my project
<Shortstop> I'm able to create one with that fetch request without an issue, and I can see it in 'rails c' console as well. I just am having a hard time wondering why the 'parties' GET result shows items, yet no locations. Its so weird
<Shortstop> This is my entity relationship diagram: https://ibb.co/1bZHRmX
<Shortstop> This is the output from Rails console: https://bpa.st/GA3VK
<Shortstop> This is the related output that is perplexing me as each of the parties have 'items', yet no 'location' tied to it...
<adam12> Shortstop: Show code.
<adam12> How are you generating the data in the browser console? That's probably the most interesting.
<adam12> bbiaf.
cartdrige has joined #ruby
<caleb> close but no cigar, those are the v1 bindings
<caleb> but they'll do as a starting point if I can't find the other one
markong has quit [Ping timeout: 260 seconds]
crax23 has joined #ruby
cartdrige has quit [Ping timeout: 246 seconds]
finsternis has joined #ruby
ur5us has joined #ruby
<Shortstop> So I reworked my project to make it so that location pretty much models the middle tier relationship like the item model
<Shortstop> When I try to make a POST request to the backend to '/parties', I get this error: https://bpa.st/OMXOS
John_Ivan has quit [Read error: Connection reset by peer]
<Shortstop> Related Party controller with byebug present in 'create' method that doesn't even hit the byebug for some reason: https://bpa.st/3V4VW
<Shortstop> Here's my current entity relationship diagram in comparison: https://ibb.co/wpwTzhS
John_Ivan has joined #ruby
<ox1eef_> Shortstop: You are calling a method that expects an argument without any arguments. It's almost impossible to help without real-world code examples. Diagrams won't help. The issue is with the code.
<ox1eef_> Hola John_Ivan - long time no see.
<John_Ivan> ox1eef_, hey there
<John_Ivan> sup
<ox1eef_> Not much. How's Christmas in Ireland?
<weaksauce> did christmas come early
<John_Ivan> Ireland?
<John_Ivan> oh
<ox1eef_> Tis the day before Christmas.
<John_Ivan> I live in Wales, the west of Britain. My ISP is part of an irish conglomerate that offers internet (magnet) so I think you likely picked up an irish IP xD
<John_Ivan> does it really say I live in Ireland?
<John_Ivan> Christmas is rolling, yeah.
<John_Ivan> Rolling with snow and cold *shivers*
<ox1eef_> Ah, interesting ! No, your IP is not visible. I just remember that from a past conversation.
<crax23> What E.II wants to do for XMass? -> resussitate like the Kryst! lol
<weaksauce> i need to dry brine my turkey if it's almost christmas
<John_Ivan> Yeshua Hrist
<ox1eef_> In Brazil Christmas is a two-day affair where the eve, and day are equally as important.
crax23 has quit [Ping timeout: 252 seconds]
<adam12> ox1eef_: Is that where you are located?
<Shortstop> The weird part is that it didn't even hit the create method, so I don't know which method is truly messed up in the parties_controller ox1eef_
<Shortstop> I did share the code above though ^
<Shortstop> I realized I didn't have the top part of that error message though, so here's the better error message: https://bpa.st/R4TFQ
<weaksauce> what are your routes
<weaksauce> that error isn't very useful
<weaksauce> other than you are not creating a party with the required parameter or something is messed up in your model
<Shortstop> The only thing I can think of is the migration for 'party'
<Shortstop> This is the 'party' model: https://bpa.st/CUNU2
<Shortstop> These are the related routes: https://bpa.st/7WMSG
<weaksauce> if you comment out everything inside of def index does the error still occur?
<Shortstop> I think I tried that but worth a shot
<weaksauce> if the error still happens there then you'd know a lot more about the why.
<Shortstop> Well, when I comment it out, I can get a bit further into my app, but I still get the same error
<Shortstop> I think I'll try a byebug into the 'index' method though and play around with it
<weaksauce> yeah time to step through the code
<weaksauce> which rails?
ur5us has quit [Ping timeout: 255 seconds]
caedmon has joined #ruby
caedmon has quit [Ping timeout: 246 seconds]
<Shortstop> Oh man, I found it
<Shortstop> It was a friggin typo aka missing a single ':' here:
<Shortstop>     has_one :location, dependent: destroy
<Shortstop> Should have been:
<Shortstop>     has_one :location, dependent: :destroy
<Shortstop> Within the Party model. Wow, crazy, wish it pointed to the model at that point though but cool, I found it
<weaksauce> that's a rough one
<weaksauce> glad you found it though
<weaksauce> i wonder if rubocop or the like would have found that or just assumed you knew better and was calling some method
<ox1eef_> adam12: Yep.
Shortstop has quit [Quit: Connection closed]
___nick___ has quit [Ping timeout: 248 seconds]
hd1 has joined #ruby
hd1 has left #ruby [#ruby]
Guest99 has joined #ruby
Guest99 has quit [Client Quit]
sam113101 has joined #ruby
caedmon has joined #ruby
caedmon has quit [Ping timeout: 248 seconds]
jmcgnh has quit [Ping timeout: 268 seconds]
inward has joined #ruby
caedmon has joined #ruby
sam113101 has quit [Ping timeout: 272 seconds]
ur5us has joined #ruby
Shortstop has joined #ruby
<Shortstop> Hey there, can anyone help me figure out how to properly access a 'location' within my project? I have a nested relationship within my 'routes.rb' found here: https://bpa.st/5CREI
_ht has quit [Quit: _ht]
<Shortstop> My related 'locations_controller' with a related byebug in the 'create' method: https://bpa.st/QYGHM
jmcgnh has joined #ruby
<Shortstop> Related byebug output where I see '.items' present for the given '@current_user', but receive a related error for '.locations': https://bpa.st/DLULE
<Shortstop> I'm wondering if this has to deal with the plurality of 'locations' in general. For a scenario like this where I want a single location for a party, does it make sense with what I have so far in the 'routes.rb' file in comparison to how i want to actually use it?
caedmon has quit [Ping timeout: 260 seconds]
caedmon has joined #ruby
<Shortstop> Party model: https://bpa.st/C2O4K
<Shortstop> Location model: https://bpa.st/OGQ2O
<Shortstop> Item model: https://bpa.st/73ERE
jmcgnh has quit [Read error: Connection reset by peer]
_aeris_ has joined #ruby
aeris has quit [Ping timeout: 255 seconds]
_aeris_ is now known as aeris
<weaksauce> Shortstop routes have little to do with the associations and how they are accessed inside a controller
<weaksauce> routes are just a thing to provide a mapping from a url to a controller action
<weaksauce> the has_many/has_one/belongs_to et. al. are the thing that setup the model's methods to access the relations
<weaksauce> shows all the methods that are created
sam113101 has joined #ruby
<Shortstop> Gotcha, but is this an issue with singular location being used?
<Shortstop> Bookmarked that for future reference weaksauce
<Shortstop> What's blowing my mind is that 'items' and 'location' have the same exact relationship. I can call @current_user.items, but can't call @current_user.location
<weaksauce> Shortstop if you can in the future have one gist with all the files separated out so you can see it all in one view
<weaksauce> gist.github.com lets you do that
<weaksauce> or you can just do it all in one paste thing
<weaksauce> where is your user model
<Shortstop> I think the problem might be that the user model doesn't have any association with 'locations': https://github.com/SamuelBanya/PartyPlanner/blob/main/app/models/user.rb
<weaksauce> there's nothing inside user that would create the methods for locations
<Shortstop> Is the following valid for the User model?
<Shortstop> has_one :location
<Shortstop> has_many :parties, through: location
<weaksauce> the only thing has_many does is create methods *on the object* it's being called from
<weaksauce> or has_one
<Shortstop> Gotcha, but is that idea above valid ^ ?
<weaksauce> off the top of my head i can't validate the data mappings you'd have to do a diagram
<weaksauce> and/or describe the relationships
<Shortstop> Gotcha, I'll just try that and see if that works to be honest, and play around with a byebug with it
<Shortstop> Thanks for helping me point to the User model though, makes sense
<weaksauce> you're welcome
<weaksauce> Shortstop the methods that are doing the things are really dumb at the end of the day and expect the data to be laid out in a proper fashion
<weaksauce> they don't do anything special wrt making sure things are correct
<Shortstop> For sure, hence why I want to play around with it with a byebug to be sure
<weaksauce> yeah when in doubt
<Shortstop> Pretty sure it'll act like 'items' in this scenario but singular though
<Shortstop> had to rethink that project today since without the user being tied to location, it would be very hard to access and make changes etc
<Shortstop> so its better to also treat it like a middleman anyway, since a person would tie a location to a party anyway. Though the ownership is slightly weird, it'll be ok for this purpose anyway
<weaksauce> learning project?
caedmon has quit [Ping timeout: 268 seconds]
<Shortstop> Yeah its just the final one I gotta do for a bootcamp
<Shortstop> It sucks because my "instructor" barely helps so it's always on my own for this bs
<Shortstop> If I had known what I know now, I wouldn't have done it, but honestly it's fine as I already got a junior job in the meantime
<Shortstop> not really with their help though, and not even related langs are used anyway
<Shortstop> Just trying to crank it out quickly though so I can just get that stupid bs done
<Shortstop> even with those relationships though, @current_user.location doesn't work, and just gives
<Shortstop> (byebug) location @current_user.location
<Shortstop> *** ArgumentError Exception: wrong number of arguments (given 1, expected 0)
<Shortstop> nil
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
markong has joined #ruby
lagash_ has quit [Quit: ZNC - https://znc.in]
cartdrige has joined #ruby
lagash_ has joined #ruby
<sam113101> "puts @current_user.location"?
budo has joined #ruby
ur5us has quit [Ping timeout: 246 seconds]
budo has quit [Quit: Leaving]
<Shortstop> sam113101 Related output:
<Shortstop> (byebug) puts @current_user.location
<Shortstop> nil
<sam113101> just @current_user.location then?
<Shortstop> isn't that what I outputted above though? sam113101
<Shortstop> (byebug) @current_user.location
<Shortstop> nil
<Shortstop> (byebug) Location.create
<Shortstop> #<Location id: nil, user_id: nil, party_id: nil, name: nil, created_at: nil, updated_at: nil>
<Shortstop> Does this mean I just have to use Location.create and provide it params including the 'user_id' and 'party_id'?
<Shortstop> (byebug) params
<Shortstop> #<ActionController::Parameters {"name"=>"New York, NY", "party_id"=>"1", "controller"=>"locations", "action"=>"create", "location"=>{"party_id"=>1, "name"=>"New York, NY"}} permitted: false>
sagax has joined #ruby
<ox1eef_> Shortstop: A location does not exist for @current_user - you will have to create one. Location.create!(user_id: @current_user.id, ...).