|
Arachnamus posted:Splatting args turns a set of discrete args into an array. If you want to pass them to another method as args (and not an array) you need to unsplat them, thus:
|
# ? Aug 26, 2014 18:05 |
|
|
# ? May 24, 2024 21:06 |
|
This is real pedantry but the self is unnecessary in that code. You can just use to_s.split.... You only need to use the self-dot notation to differentiate from local variables. Also, it's good practice to capture and pass on the block when making delegating functions. You might as well use *args, &blk in all cases. xtal fucked around with this message at 19:36 on Aug 26, 2014 |
# ? Aug 26, 2014 19:27 |
|
xtal posted:This is real pedantry but the self is unnecessary in that code. You can just use to_s.split.... You only need to use the self-dot notation to differentiate from local variables. ...I use self like this. I just don't feel safe not using it. xtal posted:Also, it's good practice to capture and pass on the block when making delegating functions. You might as well use *args, &blk in all cases.
|
# ? Aug 26, 2014 19:44 |
|
KoRMaK posted:Don't worry about it, I like hearing this stuff. Ruby code:
&blk (which could be &anything) stands in competition to yield. The difference is that yield will fail if there is no block, and the block is not assigned to a variable. With &blk, the block isn't required (the variable will be set to nil) and you have a named function object that you can wrap or pass on to other functions. When you call something with an ampersand argument it means "try to convert this object to a Proc, then pretend that Proc is a block I've just sent you." Symbols implement to_proc, which is why you can use select(&:positive?). xtal fucked around with this message at 20:05 on Aug 26, 2014 |
# ? Aug 26, 2014 19:57 |
|
xtal posted:
|
# ? Aug 26, 2014 20:04 |
|
KoRMaK posted:I'm not following what you are getting at. How would this have improved what I wrote? Can you rephrase your example in the context of the example I gave? I reworded my post a bit, not that it made a substantial difference. The idea is basically that if you're making a delegating function with *args, there's no downside to sending along the &block in addition. It'll save headaches down the road, and the delegator doesn't need to know what the receiver does or doesn't support -- it should pass along everything and the receiver should validate it.
|
# ? Aug 26, 2014 20:09 |
|
xtal posted:I reworded my post a bit, not that it made a substantial difference. The idea is basically that if you're making a delegating function with *args, there's no downside to sending along the &block in addition. It'll save headaches down the road, and the delegator doesn't need to know what the receiver does or doesn't support -- it should pass along everything and the receiver should validate it.
|
# ? Aug 26, 2014 20:18 |
|
enraged_camel posted:Thank you guys. I'm no longer contemplating suicide. Also, don't hand-configure any servers, use Chef or Puppet or Ansible or literally anything that requires you to keep your server configurations in Git and lets you build a new server in minutes instead of hours.
|
# ? Aug 26, 2014 21:21 |
|
a
DONT THREAD ON ME fucked around with this message at 03:17 on Oct 8, 2014 |
# ? Aug 26, 2014 23:05 |
|
In other news, I figured out that erb will let you do this:code:
|
# ? Aug 26, 2014 23:22 |
|
PHP thread is thataway
|
# ? Aug 26, 2014 23:32 |
|
MALE SHOEGAZE posted:In other news, I figured out that erb will let you do this: Why wouldn't it? You could probably do it in haml, too. But... Why?
|
# ? Aug 26, 2014 23:34 |
|
MALE SHOEGAZE posted:In other news, I figured out that erb will let you do this: You're a bad man for even joking about this
|
# ? Aug 26, 2014 23:37 |
|
necrotic posted:Why wouldn't it? You could probably do it in haml, too. But... Why? Because partials are obviously not enough for people, so I constantly see object methods that return "HMTL CODE".html_safe, which are then rendered in the view. I'm just surprised I haven't seen this. You could even say, define a bunch of these methods in your application.html.erb then use them whenever you want!
|
# ? Aug 26, 2014 23:58 |
|
you have made me hurt. hurt bad. So, if anyone needs a senior level rails consultant, I'll have 20-40 hours/month starting in September. Yo.
|
# ? Aug 27, 2014 00:24 |
|
MALE SHOEGAZE posted:In other news, I figured out that erb will let you do this: ...oh. OHHHH Now I see whats going on. And its recursive. I inherited RoR code that was written by some offshore people who obviously mainly program in VB. All the variables had poo poo like arrVariable in front of it (arr for Array) instead of just pluralized variable names to signify a collection. Weird loops and stuff, and badly designed everything. I never want to go back to VB or C# or .Net for work stuff.
|
# ? Aug 27, 2014 01:07 |
|
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 |
|
Tao Jones posted:Since it's not a part of the Dog database I can't just query for it with a .where. Is using scopes the wrong approach, and, if so, what would work better? This is the kind of thing that would get handled with a join.
|
# ? Aug 27, 2014 02:32 |
|
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:You can't. Rails validations are always at risk for race conditions when not backed by database constraints. Hm. What kind of constraint would work conditionally, only taking effect when we try insert something that is flag to disallow duplicates?
|
# ? Aug 27, 2014 03:33 |
|
MALE SHOEGAZE posted:Because partials are obviously not enough for people, so I constantly see object methods that return "HMTL CODE".html_safe, which are then rendered in the view. I'm just surprised I haven't seen this. That entire idea really belongs in the coding horrors thread.
|
# ? Aug 27, 2014 06:22 |
|
Safe and Secure! posted:Hm. What kind of constraint would work conditionally, only taking effect when we try insert something that is flag to disallow duplicates? A unique index: Ruby code:
|
# ? Aug 27, 2014 12:59 |
|
That won't work. That applies to part_number all the time. It has to apply conditionally and such a thing is not doable through a unique index in MySql.
Safe and Secure! fucked around with this message at 13:39 on Aug 27, 2014 |
# ? Aug 27, 2014 13:23 |
|
Safe and Secure! posted:That won't work. That applies to part_number all the time. It has to apply conditionally and such a thing is not doable through a unique index in MySql. track a secondary field that has a uniqueness constraint set to allow nils. if it meets the condition, mirror the property onto that field. If it does not, then leave that field blank. i'd also consider playing around with a multi-column unique index where the additional column is a value based on your conditional. Unless your conditional is simply checking the presence of a field, in which case why aren't you using multi-column unique indexes?
|
# ? Aug 27, 2014 15:22 |
|
Tao Jones posted:However, for the life of me I can't figure out how to also implement the parameter from the Industry class. Since it's not a part of the Dog database I can't just query for it with a .where. Join ye a table: code:
Jaded Burnout fucked around with this message at 17:50 on Aug 27, 2014 |
# ? Aug 27, 2014 17:48 |
|
kayakyakr posted:track a secondary field that has a uniqueness constraint set to allow nils. if it meets the condition, mirror the property onto that field. If it does not, then leave that field blank. A multi-column unique index won't work. My conditional could be changed to checking the presence of a field (using NULL instead of one of the two values), but we still want to prevent the insertion of ('TitleA', false) even when ('TitleA', NULL) is in the table.
|
# ? Aug 28, 2014 01:52 |
|
Arachnamus posted:Join ye a table: Thanks, this was just what I needed to get myself unstuck.
|
# ? Aug 28, 2014 02:50 |
|
Safe and Secure! posted:That won't work. That applies to part_number all the time. It has to apply conditionally and such a thing is not doable through a unique index in MySql. I don't know how feasible it is in your situation, but if you can do a migration to postgres, you could have partial unique indexes which would solve your problem. create unique index on book (Title) where (not DuplicateTitleAllowed)
|
# ? Aug 28, 2014 08:09 |
|
Anyone know of a Warden strategy compatible with Devise::Strategies:atabaseAuthenticatable? I'm investigating moving authentication off Rails to Sinatra, so Devise itself is out. It's not a terribly complicated strategy, but I wanted to double check if anyone knew of an existing one before I built it.
|
# ? Aug 28, 2014 16:44 |
|
More a REST question (followed by a breadcrumb question) than a rails question but what rules do you guys applies when it comes to REST routes? I'm trying to optimize the way I do my routes Here are my relationships so far: An account has many projects A project belongs to one account and has many units A unit belongs to one project and has many leases A lease belongs to one unit and has many events and many payments A payment belongs to a lease An event belongs to a lease I read that ideally it shouldn't be deeper than 2 levels so do those route make sense? /accounts/ /account/X/ /account/X/projects/ /project/X /project/X/units /project/X/unit/Y/ (this shows the unit details + leases) /lease/X/ (this shows the lease + payments/events) /lease/X/event/Y/ /lease/X/payment/Y/ Also, regarding breadcrumbs, I figure I need to gather all information. Right now I'm doing it in the controller with a before_filter :init_parents function that looks just like that code:
|
# ? Aug 28, 2014 17:02 |
|
I agree with most of this post about designing APIs
|
# ? Aug 28, 2014 17:05 |
|
Hi guys, small brain fart ... I have two model functions that goes like this: code:
|
# ? Aug 31, 2014 19:20 |
|
xenilk posted:Hi guys, small brain fart ... http://railsless.blogspot.com/2011/08/difference-between-nil-empty-blank.html Chilled Milk fucked around with this message at 19:53 on Aug 31, 2014 |
# ? Aug 31, 2014 19:50 |
|
xenilk posted:Hi guys, small brain fart ... If you just want something falsey, go with active_lease, otherwise !!active_lease is a common way to get an actual true/false. Otherwise use active_lease.present? which pretty much does the same thing but requires activesupport: https://github.com/rails/rails/blob...blank.rb#L4-L25 Jaded Burnout fucked around with this message at 20:13 on Aug 31, 2014 |
# ? Aug 31, 2014 20:07 |
|
This isn't strictly an answer to your question, but I'd do something like this:code:
It's the responsibility of a lease to define what "active" means. And defining active_lease as a relation rather than a method lets you avoid the N+1 problem by includesing :active_lease in your initial Lease query and not fetch it for every individual lease. i.e. code:
would only have to make 2 queries. good jovi fucked around with this message at 00:05 on Sep 1, 2014 |
# ? Aug 31, 2014 21:12 |
|
^^^^^^ holy poo poo. Thanks! I would have honestly never thought of a solution like this.
|
# ? Sep 2, 2014 14:47 |
|
How would I do automated testing for javascript? I need to verify that bootstrap is working right after an upgrade and do regression testing, so that means making sure things like modals open and respond to input correctly. Is there a way to do this in ruby or rails via automated testing? I can understand checking inputs/outputs on models and controllers and even views, but javascript seem like a can of worms. How do you describe what is acceptable passing criteria? Looking around, it seems like there are some options but nothing that is an internet favorite. I've spotted cucumber and jasmine. Are either of these great options, and if not is there something else that is?
|
# ? Sep 3, 2014 04:49 |
|
Has anyone managed to get Sass source maps working with Rails (or just Sass 3.3+)? Turns out it's pretty critical for my current project, and I'm faced with this clusterfuck involving sprockets, rails-sprockets and rails-sass. Everyone on issue trackers who's managed to get it working seems to have done so almost accidentally by managing to add just the right accidental combination of gem versions. I can get 3.whatever into my test app, but hosed if sprockets or whatever doesn't decide to play funny buggers. Spent half a day yesterday methodically bundling various different combinations, adding and removing gems and forking and updating and I am royally loving sick. gently caress
|
# ? Sep 3, 2014 10:25 |
|
KoRMaK posted:How would I do automated testing for javascript? I need to verify that bootstrap is working right after an upgrade and do regression testing, so that means making sure things like modals open and respond to input correctly. Cucumber supports JS via Capybara but that's for a specific kind of testing, namely your main business-cares-about-this behaviour. You don't want to be using it for testing all your little edge cases. Jasmine is a unit testing framework and lots of people use it. I've never found one I really get on with so I don't test my JS, but this makes me a Bad Person. I'd recommend starting with a combination of cucumber and jasmine, if you have trouble with them at least you'll know what to look for in other frameworks.
|
# ? Sep 3, 2014 12:34 |
|
|
# ? May 24, 2024 21:06 |
|
RobertKerans posted:Has anyone managed to get Sass source maps working with Rails (or just Sass 3.3+)? Turns out it's pretty critical for my current project, and I'm faced with this clusterfuck involving sprockets, rails-sprockets and rails-sass. Everyone on issue trackers who's managed to get it working seems to have done so almost accidentally by managing to add just the right accidental combination of gem versions. I can get 3.whatever into my test app, but hosed if sprockets or whatever doesn't decide to play funny buggers. Spent half a day yesterday methodically bundling various different combinations, adding and removing gems and forking and updating and I am royally loving sick. gently caress To quote someone dealing with this yesterday, "source maps are why we switched from the asset pipeline to grunt", so you're not the only one finding it difficult.
|
# ? Sep 3, 2014 12:36 |