Ignacio Alonso

Joined

3,730 Experience
36 Lessons Completed
0 Questions Solved

Activity

Posted in How to send Webhook?

+1

For anyone who wants to use Models in tasks, you should load your environment on your task to load them before using them on the code as in:

task example: :environment do
end

Posted in Rails + Javascript question

Hey guys,

I have an app for generating orders containg products. I'm currently using a “cart” through table that helps me connect both orders and products. I would like to have a list of products where users can select what they want from the list via checkbox for e.g. and then add them to an array that would be sent to my controller but I don’t want to reload page on each product add from the list. What would be the best way to add the X number of products to the params after user ’adds' them to the cart and press send?

Posted in New Ruby/Rails site with documentation

This looks good. Thanks for sharing!

Im trying to make a project to practice more kinds of associations would you kindly help me understand this?

The basic idea is to have a betting game where one user generates a new bet that can only be accepted by another user (only 2 competitors assigned for each bet, the creator and the other player).

I’m thinking about 2 tables:

users

bets

Normally I would just have a one to many relationship for the user that created the bet. But I’m confused about the ‘competitor’ column where another user is also a user with a user_id. How can I express this relationship better than this:

After thinking it through it doesn’t look like a good setup because I’m renaming a column where I’m storing the user_id and having a many to many ‘through’ model doesn’t make sense since it is a “only one competitor can participate in that bet”.

I was thinking about a ‘one to one through’ creating a ‘competitors’ table like so:

Could you explain to me how to build it in a better way?

Many thanks!

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.