#RubyOnRails - 24 July 2018
« Back 1 day Forward 1 day »
[05:00:07]
mikhael_k33hl:
Can you guys direct me to an article or guide pertaining good model creation?
[05:41:08]
sevenseacat:
the official rails guides are a great place to get started http://guides.rubyonrails.org
[06:31:45]
sevenseacat:
you can use `references` to create belongs_to associations, eg. `rails g model Book owner:references`
[06:32:37]
mikhael_k33hl:
In that case, what happens to the migrations automatically generated as well?
[06:36:35]
mikhael_k33hl:
So when I generate model User, it will create a user migration. Then I edit User for associations. Can I just run rails generate migration User?
[06:38:04]
sevenseacat:
if you want to change your database schema, you generate a new migration and name it appropriately, eg. `rails g migration add_role_to_users`
[06:41:19]
sevenseacat:
yes, you should get familiar with editing all of the code. the generators aren't meant to generate perfect code - they'll help form a starting point.
[06:42:09]
sevenseacat:
you can generate a model with belongs_to associations like I said before, but not has_many
[07:03:49]
Arkentias:
Hello ! I have a question, do you guys think there is a way for me to store lambdas in the database somehow?
[07:04:48]
Arkentias:
Yes I know that it seems crazy and stupid but in a world where this would be a good idea, how would one do that?
[07:05:42]
sevenseacat:
I don't know how you could do ruby lambdas. stored procedures in postgres would be the equivalent
[07:05:58]
tbuehlmann:
have an evil_ruby column and save a string in it, that'll be evaled later on in ruby-land
[07:08:04]
Arkentias:
Ok so we provide a product that allows for easy creation of fundraising platforms for NGOs, the idea is that users create 'projects' through which they raise money for the NGO by asking their families and friends etc
[07:08:38]
Arkentias:
But this expanded, sometimes you just "vote" for a project, sometimes you give money, sometimes you buy products, sometimes you buy a ticket, etc
[07:09:10]
Arkentias:
And this action can now be applied on a platform directly (root level), on a group of project, or on a project (or even a user)
[07:09:47]
Arkentias:
So my idea is to try to have a 'recipe' for the funnel that users go through when they want to do one of these actions
[07:10:09]
Arkentias:
This recipe would be my "Procedure" object, which already contains a JSON that allows for easy changing of the form that user go through
[07:11:02]
Arkentias:
And I'm trying to find a way to maybe have some sort of recipe in the backend for the different records to create etc depending on the Procedure, like one would create a Vote, one would create a transaction + make the User follow a project etc
[07:12:11]
Arkentias:
But indeed, the client would have to be able to play around with it through our Backoffice, so I can't just let our Vue application send Ruby code, that's a no go, absolutely
[07:12:45]
Arkentias:
Just trying to figure out how to attain a high level of flexibility without shooting my own foot
[07:13:57]
tbuehlmann:
I guess it's cool to have these things in your application and if you're ever at a point where you feel there's missing an abstraction, think again
[07:14:17]
sevenseacat:
if you want to create a new 'thing' for people to do, you're going to need to write more than a lambda in your db
[07:15:04]
sevenseacat:
we have a similar sort of thing, where we have different entry methods users can pick from, to enter a competition
[07:17:52]
Arkentias:
Ahaha ok I guess it's indeed better that way, when we need more behaviour i'll just add some methods
[07:43:56]
mikhael_k33hl:
Tried to run rails generate model, but why does my model doesn't have the right fields/attributes? https://gist.github.com/marzdgzmn/cac840acd0a87b8c955e8bf29b949428
[07:47:44]
mikhael_k33hl:
Oh okay. So regardless of what you used, either has_one and belongs_to, in the migration file, it will add only the belongs_to field to the appropriate model?
[07:48:26]
sevenseacat:
I don't see any associations there. but the difference between those two association types is which model the foreign key goes on
[07:52:10]
mikhael_k33hl:
sevenseacat: So I have the models: Hog, Supplier, Feed, and PigPen. I want to create an association for Hog belongs_to: supplier, has_many:feeds, has_one: PigPen
[07:53:53]
sevenseacat:
if a Hog has_one PigPen, then a PigPen belongs_to a Hog - you might want that to be flipped so a Hog belongs_to a PigPen and a PigPen can has_many Hogs
[07:54:45]
sevenseacat:
if a Hog has_many Feeds, then a Feed belongs_to a Hog - so the feeds table would have a hog_id field
[07:56:58]
mikhael_k33hl:
can't seem to find the rails g migration command for that: https://edgeguides.rubyonrails.org/association_basics.html
[07:58:36]
mikhael_k33hl:
I run `rails generate model #{model}` for each models. Now I want to create a migration for their associations
[07:59:13]
sevenseacat:
you could have done all of the associations when you did the models, ie. add hog:references when generating the Feed model
[08:10:50]
mikhael_k33hl:
Okay, I run `rails generate migration add_hog_to_pig_pen hog:references` now i have :https://gist.github.com/marzdgzmn/9c745e19d08748fd03c789da5f36ea7d Should I just add a has_many: to my hog model manually?
[09:14:22]
Charliebr73:
Has anyone experienced an issue where AngularJS drag and drop lists ignore the last move, i.e., not saving it to the database?
[09:15:02]
Charliebr73:
I am working on an Open Source application for an University in London. Rails 5 API and AngularJS frontend.
[09:15:37]
Charliebr73:
We are having an issue where, when moving list items, the last move is never recorded to the database. If I make only one move, that move is never recorded
[09:16:04]
Charliebr73:
You can take a look at the code at https://github.com/CLOSER-Cohorts/archivist
[09:17:40]
Charliebr73:
@sevenseacat The file I believe is creating this problem is https://github.com/CLOSER-Cohorts/archivist/blob/develop/app/assets/javascripts/sections/instruments/modules/build/controllers/constructs.coffee
[09:18:17]
Charliebr73:
@sevenseacat The Rails controller is https://github.com/CLOSER-Cohorts/archivist/blob/develop/app/controllers/instruments_controller.rb
[09:19:22]
Charliebr73:
@sevenseacat There is a function called $scope.treeOptions (Angular) that trigger a Post request to Rails 'reorder_ccs' method.
[09:19:48]
Arkentias:
Did you check in the Google Dev Tools when your updates are sent to the Rails API?
[09:20:08]
Charliebr73:
@sevenseacat I will have a go there as well but the last time I tried there, one of the guys there was incredibly rude
[09:20:48]
Charliebr73:
@Arkentias I have tried console.logging pretty much everything. From whether data was being loaded, to the changes in positions, etc
[09:21:39]
Charliebr73:
@sevenseacat "so when you move item 1 to position 3, what request gets fired?" -> The dropped function kicks in and the triggers a post request for Rails to updates the database
[09:22:23]
Charliebr73:
Just FYI, I did not build this. I inherit this code from a developer who left in December. I only started here two months later. No handing over .
[09:23:54]
Charliebr73:
It seems it only realises there has been an update from the second move onwards
[09:24:42]
sevenseacat:
can you show us some actual data, not a description of what you think is happening
[09:25:25]
Arkentias:
I think it updates the whole list everytime, not move per move, so the first "Dropped" event is apparently not handled but the rest is so when the second "dropped" event happens, the whole list is saved to the DB
[09:25:47]
sevenseacat:
load up a list of things. record their IDs. move one. note the request params that get made
[09:26:07]
Arkentias:
So the idea is to find why that first even is not handled. When you put a console.log in the "dropped" handler, the function doesn't even get called the first time, right?
[09:28:32]
Charliebr73:
The thing is, the person who wrote this, had never worked with rails or Angular before. God know why he chose those two if he had no previous experience in them.
[09:29:05]
Charliebr73:
And he was the only developer at the time so I am pretty sure more things will break as I work on the application.
[09:29:11]
Arkentias:
... I know that feel, and I can see that looking at his Rails controller. Good luck with that project
[09:30:06]
Radar:
[19:24:42] <sevenseacat> can you show us some actual data, not a description of what you think is happening
[09:31:09]
Arkentias:
The problem here is not the data guys, the problem is the AngularJS event not even being triggered, that's the first thing to fix before even thinking about the rest I think
[09:31:30]
Arkentias:
Maybe the data will be a problem after that, but if the request is not even sent to Rails, that should be fixed first
[09:32:19]
Arkentias:
That's not what Charlie is saying, the event is not triggered on the first move
[09:32:28]
Charliebr73:
@sevenseacat if that is the case, how does it work from the second move onwards?
[09:32:38]
sevenseacat:
and on the second move, its getting triggered with the wrong data, the data from the first move
[09:33:15]
Arkentias:
@Charliebr73, you did observe in the Network tab that the request wasn't send on the first move, right?
[09:33:30]
Charliebr73:
@sevenseacat Every insight is a pointer I can explore. Your help is very much appreciated
[09:49:44]
chridal:
Having some weird issues with paths. Anyone mind having a look? https://gist.github.com/valleybay/724ac6f7ebece13af7477cbb7f4c82f4
[09:56:51]
Arkentias:
Wait you get an error in the show view but the manage_room_path is in the index view?
[10:01:57]
Arkentias:
yes but the error in the gist says buildings/show.html.erb where line #29 raised: blablbal
[10:06:25]
Arkentias:
I don't think so no but that's the only weird thing I could find in the gist :p
[10:06:52]
Arkentias:
I don't think I would be able to help with those informations but maybe someone else has an idea or has already encountered a similar issue
[10:10:25]
Arkentias:
Indeed this is bit the same as in the documentation, I'm not well versed enough in Rails to tell you why though. Are you using Rails 5?
[10:12:02]
Arkentias:
It is weird to me that you don't have an index route or anything, maybe someone else has an idea on that? Because I don't :p
[10:19:07]
helpa:
chridal: How to use Gist properly: https://github.com/radar/guides/blob/master/using-gist.markdown
[10:19:56]
Radar:
You would use the singular version when you only have a single room to manage. Judging by the name of your resource there is more than one.
[10:22:31]
chridal:
Radar: Will test with 'resource' instead of resources. Maybe I'm misunderstanding that part.
[10:23:03]
chridal:
I will only be dealing with one room at a time, unless they are being listed in an index or in a buildings show page
[10:58:19]
Arkentias:
Damn and here I was thinking resources was when you declared multiple resources at once, when I myself use both singular and plural resoruces in my application.. Dumb me, glad you found the issue
[11:33:41]
jlebrech:
i want to access something i create in my initializer from anywhere in the app, do I put it in a singleton?
[14:25:02]
yoones:
Hello. I have a pb with a user model that has both a has_one and has_many documents (https://github.com/yoones/rails_has_one_has_many_bug). When a record is built through has_one, it doesn't show up in the has_many and vice versa. Any idea how to fix this behavior? Is it a bug?
[14:26:41]
yoones:
fryguy, developpers before me wrote the app this way, can't change it for many reasons
[14:27:54]
yoones:
the reason is irrelevant here, I'm just curious as to how I can make rails reflect the has_one non-persistant record in the has_many association
[14:29:58]
sevenseacat:
if you add a document via has_one, then reload the has_many, does it appear?
[14:31:43]
yoones:
maybe I should replace the build_proof_of_id with a self.documents.new(type: 'Document::ProofOfId')
[14:33:38]
yoones:
fryguy, I can't change the fact that we have a has_many and a has_one, and that the activeadmin forms send {proof_of_id_attributes: ...} params
[14:34:35]
yoones:
but maybe I can change the way we build the has_one so that it shows up on the has_many
[16:14:19]
hkais:
I am asking since I want to execute some tasks for generating docs and generating static code analysis
[16:24:24]
hkais:
read something about rdoc but also other doc systems are around. so I am a bit confused what to learn
[17:17:31]
jamesbvaughan:
I'm fairly new to rails and have a question related to git. I understand how the default .gitignore rules are set up and work, but I don't understand *why* they are what they are. For example, why is `log/` kept in git with a `.keep` file when all contents of that directory are ignored? Why not just ignore the directory completely?
[17:25:57]
havenwood:
jamesbvaughan: When the repo ends up in prod, it should have a log/ directory with nothing in it.
[17:26:31]
havenwood:
jamesbvaughan: (Nothing, other than the placeholder .keep to ensure the dir is committed.)
[17:27:44]
havenwood:
jamesbvaughan: They could have alternatively put a .gitignore file in the dirs they want to keep, with the content: !.gitignore
[17:28:34]
havenwood:
But you have to put something in the dir if you want to commit it, since git ignores empty directories.
[17:30:08]
havenwood:
And they do want to commit it, so everyone doesn't have to create the log/ dir when deploying.
[18:02:39]
jwr:
anybody know how to get unicorn to log to stdout? my first instinct was to try stdout_path "-" but that doesn't seem to log anything at all.
[18:33:56]
chkhanch:
hi2all, I have nested resources 3 lvl, at view form: form_with(model: @lesson, url: course_theme_lessons_path([@course, @theme, @lesson]). after click 'submit' take url like: "/courses/1%2F3%2F4/themes/3/lessons". Why added %2F3%2F4/? at url
[18:57:28]
syndikate:
` label onclick="javascript:window.location.href='#{url_for(params.permit(:limit, :q => [:name_cont, :title_cont, :deleted_at_present]).merge(limit: limit))}'"`
[19:15:17]
dachi:
Hi I'm trying to share sessions between subdomain and domain, and have isolated sessions on different subdomain.
[21:09:07]
blindMoe:
with rspec, when I am allowing a class to receive a function call and that same function is called with multiple different params, is it possible to have an assertion only check against specific arguments? Right now it will tell me that it expected to receive foo('bar') twice but received foo('asdf') 4 times and foo('bar') twice
[23:50:35]
dachi:
Please help me. I'm trying to isolate one domain from cookie session store. I need lvh.me and a.lvh.me to share sessions, and I need b.lvh me to be completely isolated from those two.
[23:51:35]
dachi:
I've been struggling with middlewares and other things for a long while, and I was messing my project up. Two rules like ".b.lvh.me" and ".lvh.me" completely ruin app as ".b.lvh.me" gets into ".lvh.me" scope :(