|
I'm fairly new to Rails and I'm trying to use it to make a web-based wargame. I was building a database to represent all of the countries (board spaces if this were a real game) with columns for each of the things a country has - player1 troops, player2 troops, and so on, with the idea that playing the game would be the machine updating each of those columns as the board state changes. However, I realized as I started doing it that this would mean the database would be constantly changing, so there couldn't be multiple games. So now I'm thinking that each game would begin with creating a new database "foo" from template "bar" where foo is an automatically sequencing number(ie, game000001, game000002, etc) and bar is the original database. However, this is a little out of my comfort zone and I don't know if that's a good idea or if there's a better way, and Google isn't turning up anything helpful. Is this a sane way to approach the problem? (Obviously I would need to have the server clean itself up periodically since I don't want scads of completed/zombie game databases laying around.)
|
# ¿ May 1, 2014 04:15 |
|
|
# ¿ Apr 27, 2024 11:55 |
|
kayakyakr posted:That's a horrible way to design this. Horrible. Thanks, that's helpful. I got hung up thinking that there should be a Countries table that keeps track of who has what where, but thinking about it in the way you suggest makes a lot of sense.
|
# ¿ May 1, 2014 07:37 |
|
I have a weird situation with ActiveRecord associations, and since Rails is fighting me tooth and nail on what I'm trying to do, I get the sense I might be approaching it the wrong way. (Class names have been changed to protect the innocent.) I have a chain of has_many through, like so: code:
What I want to do is have a method on Dog that finds all of the dogs that match the parameters passed in, all of which are optional. One of those parameters can be an industry name, so the method could find all is_fuzzy poodles where the related industry is widgets. I approached making a search that can find various Dogs like this: code:
fantastic in plastic fucked around with this message at 02:26 on Aug 27, 2014 |
# ¿ Aug 27, 2014 02:24 |
|
KoRMaK posted:You mean they are in different Database or different tables? They're all different tables in the same database, sorry.
|
# ¿ Aug 27, 2014 02:45 |
|
Arachnamus posted:Join ye a table: Thanks, this was just what I needed to get myself unstuck.
|
# ¿ Aug 28, 2014 02:50 |
|
Some poor idiot will actually pay for that? Clearly I'm in the wrong business and should stop everything, make a clone of RubyMonk that includes "competence tests" and charge people a couple hundred bucks to get the Tao Jones Ruby Institute Silver Star or whatever.
|
# ¿ Nov 19, 2014 05:53 |
|
KoRMaK posted:Thanks, but I'm not sure this will apply to my situation. Doing current_account.users builds a query that is "select * from users where account_id = 1" (1 being the id of current_account). I'm not sure I understand the question. Ruby code:
Ruby code:
|
# ¿ Nov 23, 2014 21:15 |
|
What happens if Alice puts Bob's email address in the "user fills in the email address of the old account" step?
|
# ¿ May 3, 2015 04:10 |
|
kayakyakr posted:Seems like Bob would get an email asking him to claim his account? Ah, okay. From the way I was reading the flow, it seemed like there'd be an AccountClaim with Alice's user_id and Bob's email address, which might be dangerous if Alice is evil and tricks Bob.
|
# ¿ May 3, 2015 04:40 |
|
Tangential to the testing conversation - is there a best practice for a situation like when your client has an API, you're building a new application that consumes that API, but the client's documentation is poo poo and the API often doesn't behave as specified? It's not exactly the same case as we're discussing here, but a company I've worked with has tended to use tests touching the API to persuade intransigent clients that their API is, in fact, not behaving to specification. It tends to drive developers crazy because it can be hard to tell if the test is badly written or the API is wrong.
|
# ¿ Jun 27, 2015 03:02 |
|
If you plan your career well, you can be long gone before any of the lovely technical decisions and kludges you made to get version 1 working ever come back to bite you.
|
# ¿ Jul 11, 2015 01:00 |
|
Peristalsis posted:ajax issue So, if I'm understanding your description, you've got one AJAX call that's something like GET api/whatevers?q=foo that you fire off when a user selects an option in a select box. The API does whatever it does to handle that request and sends you the results, which you're setting to a variable and then using that variable for other code, which you theorize is executing before your variable is set. You could try sticking your code that needs the variable into something like this: code:
|
# ¿ Aug 8, 2015 03:58 |
|
code:
|
# ¿ Jan 23, 2016 19:54 |
|
Waroduce posted:annnnd I'm not really sure where to go from here....and I don't really get hashes but i know I need something like As he lay dying, the last living descendant of the last Aztec high priest whispered: code:
Then you'll have to figure out how to do whatever the end goal for the program is, which I guess is go to a webpage and click particular checkboxes to autofill a form?
|
# ¿ Dec 6, 2016 04:16 |
|
Waroduce posted:Can you explain your code to me in plain English and how it fits into what i've got? Sure. A hash like code:
My snippet should let you loop through all of the elements in a hash and print the key and value for each. My intention in posting it was to try to demonstrate that you'd need to read each element and that you can work with the keys and values individually. I apologize if the way I went about it was too opaque; I thought you were a junior dev rather than someone trying to write something for the first time. If you play around with the snippet, you should be able to construct an if-statement which will shovel all of the "y" values into another array of hashes rather than calling puts (which just displays them to the screen). Then you could do something like loop over that new array, split your keys into, eg, ["PT", "Staff"] and then have some if-statements that do something with that to record which checkboxes need to be checked. Then you'd have a scraper or something navigate to your website and check things appropriately.
|
# ¿ Dec 6, 2016 05:43 |
|
Waroduce posted:I have soccer tonight so will look at this later or tomorrow, but I'm not using ruby by choice, it's what we use to run all of our scripts in my department so yeah Ruby on Rails was big 4 years ago. It lets you do a really specific thing (basic CRUD web app/api) really easily if you're willing to adopt the Rails Way To Do Things. A fair amount of consultantware/internal tools/random web APIs are built in it, but of all of the modern web stacks it's among the worst for performance. It's an unusual framework to know because it isn't, to my knowledge, taught in CS programs. It became popular with Silicon Valley startups and consulting firms. Most of the hardcore Ruby people I know are either self-taught or picked it up by chance on some consulting contract.
|
# ¿ Dec 7, 2016 04:16 |
|
|
# ¿ Apr 27, 2024 11:55 |
|
xtal posted:Just use minitest like our lord dhh gave you. Rails is omakase, and all I think my company's CTO unironically holds this position.
|
# ¿ Aug 25, 2018 02:29 |