|
For those of you that are very familiar with Inherited Resources, I'm having a problem modeling the following association chain in my controllers: Say I have Users which belong to many Leagues and each user has a single Team for a particular league. The league is identified by a slug as the subdomain, and since there is only a single team for a particular user and league, I don't need to identify that either. So instead of a URL that looks like http://example.com/leagues/1/teams/1, I get http://myleague.example.com/team, which looks a hell of a lot better to me. The problem I ran into with Inherited Resources is describing the relationship between a league (identified by the slug in the subdomain), the logged in user, and a team singleton using its idioms for describing the associations without having to resort to hacky poo poo like before_filter hooks and injecting ID attributes in the params hash. It really seems that something like this would work: code:
|
# ¿ Feb 2, 2012 17:57 |
|
|
# ¿ Apr 27, 2024 13:40 |
|
Kim Jong III posted:Hi Rails people! I'm going to be picking up RoR soon for my job. Does anyone have any recommended tutorials that are focused on someone who has plenty of experience under their belt? If you're going to be using ActiveRecord as your ORM, I highly suggest using Squeel. The AR query methods aren't completely horrible, but get verbose very quickly. If you're doing the "skinny controller, fat model" thing, it'll make the sea of scopes you'll invariably end up with 100 times more readable, and up much less space. To make your stay at Rails more pleasant, check out these guys' projects on Github to see if there's anything you might want to use: https://github.com/plataformatec https://github.com/josevalim https://github.com/collectiveidea I personally wouldn't fly without inherited resources, has_scope, and responders again, namely. Coming into Rails, I was initially depressed by how much code repetition there was in controllers.
|
# ¿ Feb 23, 2012 15:47 |
|
Apparently I haven't made the effort to understand the semantics of nested vs. scoped resources enough to know whether I'm structuring my routes and controllers wrong. I'm sure it's incredibly basic, but I made some assumptions early on that made things kind of messy. When you have an association like "a blog post has many comments", it's obvious that you'd use a nested resource since comments are always accessed in the context of a post. With the case of something like "a department has many employees", the department context is optional. I wanted to have "pretty" urls, so at the time I felt I needed 2 controllers: one that's unscoped and one that's always scoped to a department. Obviously you could combine them in one controller, but I didn't want to do something like: code:
code:
This is just a simple example, but the dataset I'm working with is necessarily highly relational and there are much more complex relationships than this. After some time, I started drowning in specialized controllers whose only real difference was in what table(s) they're performing a join to (or not). So where's the middle ground between flexible, "pretty" routing with lots of specialized controllers and a single, swiss-army-controller that handles all your scoping and filtering needs? Writing this post makes me feel like I'm really bad at Rails. Thoom posted:Disregarding my brain fart about scoping rules, I still think it's dumb how poorly documented the scoping of various namespaces is in Rails. Big Nubbins fucked around with this message at 23:30 on Apr 5, 2012 |
# ¿ Apr 5, 2012 23:25 |
|
I think I found the "middle ground" I was seeking earlier in the form of the has_scope gem. Still, I'd like to know what "The Rails Way" is to keep that poo poo DRY. Speaking of scopes, is there a gem that evals your models to provide basic sorting, filtering, and association scopes? Hobo's Scopes module is pretty much right on the money, but without the reliance on method_missing to work the magic for you. The API I'm putting together is pretty heavy on the sorting and filtering, and it's getting to the point where the majority of my model class definition consists of scope definitions.
|
# ¿ Apr 6, 2012 01:18 |
|
I think I did a bad thing. This morning, mysteriously my rails server wouldn't start. It was bombing out with the message /Users/ShameBoner/.rvm/gems/ruby-1.9.3-p286@rails_3_2/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- trace_nums (LoadError). I suspect that I properly hosed my gemset by doing a bundle update while rubygems.org's dependency API is down. I'm not sure what gem is responsible for the TraceNums class, but it seems to be missing. Is there any way to un-gently caress this gemset? For the time being, I had to go back to using my 1.9.2 version of Ruby.
|
# ¿ Oct 19, 2012 17:03 |
|
A MIRACLE posted:Wow, that seems kind of awkward, I didn't know people still inlined ruby in their javascript code. I hate to recommend js frameworks since it seems like you're already really far along with this method, but I've been really happy using either Angular, Backbone, or Knockout.js (with underscore.js as a utility belt) for my ajax-y goodness. I'd also give Spine.js a look as an alternative to Backbone. Spine is written in Coffeescript, has no dependencies, and is teeny tiny. After learning Coffeescript, I found that it made me love Javascript more, but also never want to write Javascript again, if you know what I mean. There are some ugly parts of the syntax (mixed array/hash objects, I'm looking at you), but I find it much more readable, concise, and faster to write. Unlike Backbone, Spine doesn't really have a concept of a view, so you must plug your own templating solution into it. I use HAML/Coffeescript through the awesome haml_coffee_assets gem.
|
# ¿ Oct 24, 2012 17:24 |
|
In ActiveRecord, Is there a good way to coalesce two (in this case) associations with the same model to form another, cleanly? If I lost you, here's what I'm trying to do: I have a Transaction model that's acting as a sort of audit log for transactions of virtual currency within the software. The Transaction model has two polymorphic attributes: receivable and payable. Think of a receivable or payable as "an entity that can pay or receive currency". In this case, my User model has two associations with Transaction: credits where the User is a receivable and debits where the User is a payable. What I want to do is have a third association, transactions that coalesces credits and debits. I want it to be an association and not simply a method on User so I can chain and scope it. I'm having a REALLY hard time writing an association definition that should read like "has many :transactions where User is either a receivable or a payable".
|
# ¿ Nov 3, 2012 00:01 |
|
Is there a way to set the version of SSL used when you set "config.force_ssl" to true in Rails 3.2? I'm forcing SSL in my configuration and having an issue with requests to our payment gateway timing out. For what it's worth, we're using ActiveMerchant. We managed to reproduce the issue in the following script: code:
Edit: Never mind, I found out that I can simply monkey-patch the SSL version into ActiveMerchant::Connection's "configure_ssl" method. Big Nubbins fucked around with this message at 17:38 on Dec 20, 2012 |
# ¿ Dec 20, 2012 16:51 |
|
|
# ¿ Apr 27, 2024 13:40 |
|
Smol posted:Hope you're not using OpenSSL::SSL::VERIFY_NONE in the real app. God no, that was just a sample script set up for testing. I ended up fixing it by forking ActiveUtils (ActiveMerchant dependency) and setting the SSL version in the same place it's setting the rest of the SSL options.
|
# ¿ Dec 21, 2012 20:58 |