|
I"ve poked around Clojure stuff just to see what all the 'hype' was about, didn't hook me in. But I have become more and more interested in giving Elixir a whirl. I'm blessed with having to build lots of small and varied standalone apps and less the hulking aged monoliths so I haven't burned out on Rails yet. At least there's Lotus now for when that day comes and I want to stick with Ruby
|
# ? Jul 11, 2015 16:11 |
|
|
# ? May 3, 2024 16:11 |
|
I've been getting into Elixir lately too, the language creator (Jose Valim) is a core Rails contributor and the author of Devise authentication gem. The whole language runs on the Erlang VM (usually called BEAM), the syntax has some Ruby influences but the language is functional so in reality there is not so much crossover, still it's very interesting to learn especially if you want to build a system that can scale easily. The performance of the Phoenix web framework (basically Rails of the Elixir world) is awesome, you can see requests being served in microseconds.
|
# ? Jul 11, 2015 16:43 |
|
I have an ActiveRecord question for you guys. I have 3 models - Trips - Departures (Basically locations where buses leave from) - DepartureDates (Links Departures + Trips and mentions a date and time) I'm getting the trips with an upcoming departuredate with this statement: Trip.joins(:departure_dates).where("departure_dates.leaves_on > ?", Time.now) I want to add something to that statement so I only get the trip once and the departure that's closest to the current time. I'm thinking I need some sort of group by, but other than that I'm kind of lost right now...
|
# ? Jul 11, 2015 17:31 |
|
This feels like you want DISTINCT ON (which is not the same as just DISTINCT), but I dont know how you get that through active record.
|
# ? Jul 11, 2015 18:02 |
|
Pardot posted:This feels like you want DISTINCT ON (which is not the same as just DISTINCT), but I dont know how you get that through active record. If you're using Arel 6 (so Rails 4.2 and up) there's an Arel method for distinct_on. code:
|
# ? Jul 11, 2015 18:47 |
|
I'm setting up our project on a VM on my computer so I can work from home. I can't run rake db:setup, because the rake task is trying to use the test database, instead of the dev one. I've addedcode:
For now, I've changed the test entry to be the same as development in database.yml, which did get me past this issue, but I'd like to understand what I'm doing wrong. (And fix it, of course.)
|
# ? Jul 15, 2015 17:32 |
|
Peristalsis posted:I'm setting up our project on a VM on my computer so I can work from home. I can't run rake db:setup, because the rake task is trying to use the test database, instead of the dev one. I've added I believe rake db:setup does both production and test databases at the same time.
|
# ? Jul 15, 2015 19:04 |
|
kayakyakr posted:I believe rake db:setup does both production and test databases at the same time. Yeah, db:setup will create everything in one fell swoop.
|
# ? Jul 15, 2015 19:12 |
|
Our other programmer (the UI guy, sort of) left, and now I have to maintain his code. Naturally, I immediately have a problem I haven't seen before. They symptom is this: one of our forms has a list of files that is generated after the user selects an option on a pulldown box. This list shows up as it's supposed to in Firefox, but does not show up in Chrome. After poking through his code, here's what I think is going on: There's a jQuery function assigned to the change event of the pulldown widget. This function uses an Ajax call to the form's controller to create an array of file info in an instance variable (@type_headers). The other javascript that runs in the view now depends on this controller instance variable being available in the view to populate the list of files. However, since the 'A' in Ajax stands for Asynchronous, there's no guarantee that this variable is ready before it's used in the other script. Apparently, Firefox is more likely to have it ready before it's used than Chrome is - presumably, they implement JavaScript differently. One piece of supporting evidence I have for this theory is that I did get the files to show in Chrome one time, when I had a bunch of debugging and alert statements in the code. I assume it just stalled things long enough for Chrome's JavaScript interpreter to catch up. If this is too hard to follow, let me know, and I'll try to draw a picture to clarify. 1) Is it even possible that it's doing this, or do I have to be misunderstanding the code somehow? 2) Is there an obvious fix?
Peristalsis fucked around with this message at 18:34 on Aug 7, 2015 |
# ? Aug 7, 2015 16:18 |
|
Async errors are incredibly common but I don't think that's what you're dealing with. I might be misunderstanding though.Peristalsis posted:This function uses an Ajax call to the form's controller to create an array of file info in an instance variable (@type_headers). This doesn't make any sense. A javascript function can't load data into a ruby instance attribute. What you could be doing is loading the list of file info into whatever (if any) literal string value the instance variable is at the time the ERB is compiled. Or if you mean that both scripts are making ajaxing requests to the controller: keep in mind that each request instantiates a new controller. So, you can't have two requests trying to share data across an instance variable. reread your post: Basically, my second point: It sounds like you're trying to share data from multiple requests across an instance variable. That's not going to work. I don't know why it is working. DONT THREAD ON ME fucked around with this message at 19:27 on Aug 8, 2015 |
# ? Aug 8, 2015 03:08 |
|
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 |
|
MALE SHOEGAZE posted:Async errors are incredibly common but I don't think that's what you're dealing with. I might be misunderstanding though. Tao Jones posted: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. I probably wasn't clear, and it's still possible I'm fundamentally mis-understanding the code, but let me try to clarify, if only for the entertainment value. There's some pseudo-code at the bottom, if that's easier. There's a form with an AJAX call that is routed to a method in the form's controller. That method uses the incoming data to populate an instance variable, which Rails automatically makes available back in the form. The form then uses that variable (@type_headers) to determine what to add to the form's display. This seems to work okay in Firefox, but in Chrome, when the view code moves on (since it doesn't have to wait for the AJAX call to finish) and tries to use that instance variable to determine which parts of the form to show or repopulate, the variable hasn't been created yet (or at least it isn't available to the form yet). It's like a bad hack on a comp 101 assignment to get around figuring out the entire point of the assignment. Did I mention that extensive testing wasn't the forte of the developer who originally wrote this? Neither was elegant design. Tentative resolution: In any case, someone finally pointed out to me that I can retrieve the same info just using JavaScript to send a post command instead of using AJAX, and it should be synchronous by nature. I haven't tried to implement it yet, but I'll jump on it first thing Monday. And this is a simplified version of how the code is set up. This code is for entertainment purposes only. Do not attempt to use this code at home. Form pseudo-code: code:
code:
code:
Peristalsis fucked around with this message at 20:47 on Aug 8, 2015 |
# ? Aug 8, 2015 20:43 |
|
I'm having my first real encounter with ruby and I have what is probably a really retarded question. Why does this ERB template not do what I expect? It's being run through Chef, if that matters:code:
code:
code:
|
# ? Aug 26, 2015 15:43 |
|
What is the contents of the @config hash there?
|
# ? Aug 26, 2015 15:49 |
|
Docjowles posted:I'm having my first real encounter with ruby and I have what is probably a really retarded question. Why does this ERB template not do what I expect? It's being run through Chef, if that matters: What if you replace the whole thing with code:
This is really a Rails thread, but there doesn't appear to be a general Ruby thread, or a Chef thread, so whatever.
|
# ? Aug 26, 2015 15:54 |
|
... son of a bitch. Apparently I just needed to post this and go walk around the building for 5 minutes. Got it working, it had nothing to do with the ERB syntax at all. Was just using Chef wrong. Thanks for the tips, all.
|
# ? Aug 26, 2015 15:58 |
|
Docjowles posted:... son of a bitch. Apparently I just needed to post this and go walk around the building for 5 minutes. Got it working, it had nothing to do with the ERB syntax at all. Was just using Chef wrong. Thanks for the tips, all.
|
# ? Aug 26, 2015 16:00 |
|
The last project of the developer who just left our team was to take our controlled vocabulary (e.g. valid options to use to populate a pulldown menu), which was defined in constant arrays in each model, and put it all into a single table, with columns for the class, the filed the options are for, and the term itself. The idea is that we can now add/delete/modify these vocabulary terms dynamically, without the need of a release, or even of restarting the server. So, we went from this: code:
code:
My questions: 1) For our next release, I'm planning to replace each validates_inclusion_of validation with a custom method that retrieves the list dynamically. This seems to work in my testing so far. Is there a better approach, or any reason that this is a bad idea? I know this will slow down performance, but I doubt that it'll be significant, and I don't really see an alternative. 2) We're going ahead with the current release despite this problem. Even with this flaw, the system won't work any worse than before, and any changes to the controlled vocabulary have to come through us anyway. So, is there a way to force Rails to reload a class definition? If so, does it have any risks or side-effects (e.g. affect related or connected classes)? I know you can reload an ActiveRecord object, but classes don't seem to recognize the reload method. 3) Is there a better overall approach we should have used from the beginning? Peristalsis fucked around with this message at 18:47 on Aug 26, 2015 |
# ? Aug 26, 2015 18:44 |
|
Peristalsis posted:The last project of the developer who just left our team was to take our controlled vocabulary (e.g. valid options to use to populate a pulldown menu), which was defined in constant arrays in each model, and put it all into a single table, with columns for the class, the filed the options are for, and the term itself. The idea is that we can now add/delete/modify these vocabulary terms dynamically, without the need of a release, or even of restarting the server. This is happening because your "in" statement is being run at load time since it's declared directly on the model. use: code:
|
# ? Aug 26, 2015 19:40 |
|
kayakyakr posted:This is happening because your "in" statement is being run at load time since it's declared directly on the model. Yep, you just need to wrap it in a lambda do that it's evaluated every time it's run, not just at load time.
|
# ? Aug 26, 2015 20:44 |
|
kayakyakr posted:This is happening because your "in" statement is being run at load time since it's declared directly on the model. Thanks for the reply. When this validation is hit, the code is now throwing this error: code:
Two things to note - 1) I've never used lambdas before, so I may be missing something easy and obvious, and 2) if it matters this is in Rails 3.2.something, not Rails 4. I'm going to do some Googling to see what I can find, but if there's an easy error/fix to point me to, I'd be much obliged. Edit: It may just be an issue with the space separating the second arrow and the opening curly brace. Peristalsis fucked around with this message at 21:27 on Aug 27, 2015 |
# ? Aug 27, 2015 21:23 |
|
Peristalsis posted:Thanks for the reply. When this validation is hit, the code is now throwing this error: Where is it hitting that? Post the stack trace.
|
# ? Aug 27, 2015 21:25 |
|
The Milkman posted:Where is it hitting that? Post the stack trace. Removing the space after the second arrow let me get to the new object page, but submitting the new object still raises the same exception: code:
code:
|
# ? Aug 27, 2015 21:42 |
|
Peristalsis posted:Removing the space after the second arrow let me get to the new object page, but submitting the new object still raises the same exception: Try this: code:
|
# ? Aug 27, 2015 21:50 |
|
The Milkman posted:Try this: That seems to work, thanks! Do I need anything other than reading about procs and lambdas in ruby to understand how and why this works? I already understand that we're assigning a function to the validation instead of assigning the static results of calling that function once, but I'd like to know why the first attempts didn't work, why we need the whole :in clause explicitly in a hash, what the differences are between proc and lambda, etc. Also, thank you for introducing me to the "stabby lambda" operator. Learning that name was probably the highlight of my week.
|
# ? Aug 28, 2015 16:21 |
|
Peristalsis posted:That seems to work, thanks! The hash around the in clause shouldn't be required. Ruby will automatically hash up a collection of inferred keys and values that are in an arguments array. This may be wonky below Ruby 2. Stabby lambda usage may also be wonky in rails 3. I was running under the assumption that you were on ruby 2, rails 4. UPGRADE YOUR PROJECTS!
|
# ? Aug 28, 2015 17:05 |
|
kayakyakr posted:The hash around the in clause shouldn't be required. Ruby will automatically hash up a collection of inferred keys and values that are in an arguments array. This may be wonky below Ruby 2. Yeah, from just looking at it, it seems okay, but it's not the first time I've come across needing the explicit {} even in Ruby 2/Rails 4. I'd think the stabby would work with those in, but I figured proc would be extra safe
|
# ? Aug 28, 2015 18:01 |
|
kayakyakr posted:The hash around the in clause shouldn't be required. Ruby will automatically hash up a collection of inferred keys and values that are in an arguments array. This may be wonky below Ruby 2. We are using Ruby 2.1.1 (at least, that's the version on my dev environment, prod might be slightly different). kayakyakr posted:UPGRADE YOUR PROJECTS! I'd love to, but as the only developer for 3 projects, with another 1-2 projects starting soon, there's not much chance of being able to stop doing enhancements and bug fixes so I can make an upgrade that only I care about, and that, if we're lucky, will leave us exactly where we are now in terms of features, and if we're not lucky, will leave us with a bunch of new bugs. I am doing a small project at home in Rails 4, and I hope that will give me some experience with it for when we do have to migrate the current projects, and so I can use current stuff on the new projects we have coming. It could be worse, our recently departed developer went to a company still on Rails 2 for their product.
|
# ? Aug 28, 2015 18:23 |
|
Peristalsis posted:It could be worse, our recently departed developer went to a company still on Rails 2 for their product. oh god how
|
# ? Aug 28, 2015 20:43 |
|
A Big... Dog posted:oh god how Yeah, but don't worry - it's only security software.
|
# ? Aug 28, 2015 22:16 |
|
One of the .html.erb files I'm modifying has a couple of comments with extra dashes in the delimiters: <!--- comment here --->. It seems to work like other comments, except that it's confusing Sublime Text, which doesn't recognize the ending delimiter with the three dashes, and shades everything until the next correct end-comment delimiter as a comment. I don't see anything on Google about it, so I assume the guy who coded this just had a brain fart, but I wanted a quick sanity check to make sure it's not some special form of an HTML comment, or something meaningful to Rails.
|
# ? Sep 1, 2015 15:01 |
|
Peristalsis posted:One of the .html.erb files I'm modifying has a couple of comments with extra dashes in the delimiters: <!--- comment here --->. It seems to work like other comments, except that it's confusing Sublime Text, which doesn't recognize the ending delimiter with the three dashes, and shades everything until the next correct end-comment delimiter as a comment. I don't see anything on Google about it, so I assume the guy who coded this just had a brain fart, but I wanted a quick sanity check to make sure it's not some special form of an HTML comment, or something meaningful to Rails. Pretty sure that's just a mistake. All erb really cares about is <%, <%= and the inverse of each. The parsing issue sounds like a bug with sublime text.
|
# ? Sep 2, 2015 06:53 |
|
Peristalsis posted:It could be worse, our recently departed developer went to a company still on Rails 2 for their product. We have a customer still proudly running REE and Rails 1 in production with no plans to change.
|
# ? Sep 2, 2015 16:52 |
|
aunt jemima posted:We have a customer still proudly running REE and Rails 1 in production with no plans to change. You know, I really need to remember to ask what versions of software are being used at the next job I apply/interview for. I guess using legacy systems and old tools is probably the rule rather than the exception, but I at least want to make sure I know what I'm getting into. And they should at least have given some thought to a migration plan, beyond "I guess we'll probably have to change at some point".
|
# ? Sep 2, 2015 17:21 |
|
Having a good time with the Furry Stormtrooper at Windy City Rails
|
# ? Sep 18, 2015 15:55 |
|
Is anyone here good with Nokogiri? I'm having an issue using XML DocumentFragments. Specifically, say I have code:
But, frag doesn't recognize that it has elements, even though doc does: code:
code:
Edit: Wow, frag's first child node even knows it's an element: code:
Peristalsis fucked around with this message at 16:17 on Oct 6, 2015 |
# ? Oct 6, 2015 16:00 |
|
Peristalsis posted:Is anyone here good with Nokogiri? I'm having a bit of trouble replicating your results: code:
|
# ? Oct 7, 2015 16:37 |
|
logical-fallacy posted:I'm having a bit of trouble replicating your results: Weird. I'm using the following versions: Ruby: 2.1.1p76 Rails: 3.2.15 Nokogiri: 1.6.3.1 I haven't deliberately changed any Nokogiri settings. I guess I should try updating Nokogiri. Edit: Yep, bundle update nokogiri did the trick. Peristalsis fucked around with this message at 16:50 on Oct 7, 2015 |
# ? Oct 7, 2015 16:44 |
|
Peristalsis posted:One of the .html.erb files I'm modifying has a couple of comments with extra dashes in the delimiters: <!--- comment here --->. The ERB tmLanguage bundle is embedding text.html.basic in its definition so it looks like this behavior is defined in the standard HTML tmLanguage bundle. It looks like having two dashes in a row that are not a part of the comment start or comment end delimiter is technically against the HTML spec. I never realized it was so stringent, never run into any problems from that myself before.
|
# ? Oct 7, 2015 17:07 |
|
|
# ? May 3, 2024 16:11 |
|
logical-fallacy posted:The ERB tmLanguage bundle is embedding text.html.basic in its definition so it looks like this behavior is defined in the standard HTML tmLanguage bundle. I'm not sure what you're saying here. In any case, I just changed the triple-dashes to double-dashes, and I don't think it caused any problems.
|
# ? Oct 7, 2015 17:27 |