eelcoj

Joined

8,350 Experience
0 Lessons Completed
10 Questions Solved

Activity

Posted in Stripe gems: Koudoku or Payola

Tried Payola over a year ago. But looking into how they want me to add thing's, I've found it's faster to use the API. I also think it adds even more to the "magic" (so you do not 100% know how things work).

Posted in link_to question

My first thought is that your associations are not set correctly (ie. Project, has_many :tasks / Task, belongs_to :project). From there you should be able to set, like @tasks.first.project.id or in #show @task.project.id.

Unrelated to the question, but: it might be useful for you to put your scope(s) into the model, along the lines of: scope :due_today, -> { where(due_date: DateTime.now) }. You can use these scopes then like: @project.tasks.due_today.

Thanks both Chris and Jacob. Really helpful. ๐Ÿ™Œ I got some viewing and reading to do.

Consider the situation where a model is created to which the data needs to manipulated/worked with right after creation. For instance find (*match) a certain string from a long string, convert (parts of) the long string to PDF, upload some attachments to S3, etc.

The most obvious way to me, would be to put all this separate model's methods in a background worker.

But I was also thinking of extracting these methods into some rake task (which can then also be moved to a background queue).

Basically just curious if there are other ways to go about this. Maybe I am overthinking, but who knows (at this time of the yearโ€ฆ ;)).

Posted in A `has_one :through` association issue

Thanks again, Jacob. Makes way more sense to go about data/models/associations that way. I always went for the more "visual" way to make it easier to grasp. โœ”๏ธ

Posted in A `has_one :through` association issue

Thanks Jacob, interesting point where you go about it in a completly different way. I look at the models from "top to bottom". Where Receipt is "leading". Fyi. There's also an Account model who has_many :receipts. So an Account could have many Receipts and have one Company. The reason I have an extra join model is so that I don't have duplicate Companies in my DB.

How's my thinking here?

I need try your solution and have to make some changes to my DB for that. Will report back later. :)

Posted in A `has_one :through` association issue

Can't edit above post. Just to clarify: there are models above respectively: 'Receipt', 'Seller' and 'Company'.

Posted in A `has_one :through` association issue

Hi there, I just subscribed to GoRails and it has been really helpful so far already. ๐Ÿ‘

I've been unsure about how to tackle the following situation.

Imagine a Receipt model. It can have one Company. The Company can be added upon creation of the Receipt or added/edited later.
We don't want a simple has_one in Receipt. Since Companies can belong to many Receipts. This makes all sense, I hope.

I would go about it this way:

Receipt.rb
has_one :seller
has_one :company, through: :seller
Seller.rb
belongs_to :receipt
belongs_to :company
Company.rb
has_one :seller

Now this gives me an issue in edit with the receipts_controller, where I have build_company in the case no Company is set yet. The error is undefined method 'build_company' for #<Receipt:0x007fea82677298>. While I would definitely expect that to be possible at this stage.

Am obviously overlooking something, but I can't figure it out at this stage anymore.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.