|
Sub Par posted:This is what I originally had, but because of the way Heroku works, I was getting nothing but 10.xx.xx.xx IPs that were likely some kind of Heroku load-balancing or whatever. Anyway I'm now trying this: Might want to double check that conditional assignment there. That looks like it should just be an || not an ||= for what you're trying to do.
|
# ? Jul 25, 2014 22:18 |
|
|
# ? May 8, 2024 16:33 |
|
kayakyakr posted:ruby-debug and debugger are built in to ruby 2, no? debugger statement works as if you had the debugger gem installed. code:
code:
|
# ? Jul 26, 2014 00:56 |
|
Ruby code:
|
# ? Jul 26, 2014 01:33 |
|
e: ^^ or this e2: experimenting in rails, this makes strange things happen for me. Continuing winds up stopping on every action. Still, I would think that there should be a gem making use of native debug for a quick debugger statement. Arachnamus posted:
Yup, ignore what I've said, use byebug for everything. kayakyakr fucked around with this message at 01:49 on Jul 26, 2014 |
# ? Jul 26, 2014 01:35 |
|
Good to see how to invoke the native one. They're all a bit flakey, I guess due to Ruby (or the community?) lagging behind the rest of the world when it comes to using debuggers. Given what you've said about use in Rails, I'll keep an eye on it and hope it improves.
|
# ? Jul 26, 2014 10:01 |
|
since apparently ruby's standard library doesn't have a priority queue (!), whats a solid gem for priority queueing?
|
# ? Jul 29, 2014 20:30 |
|
https://github.com/boborbt/priority_queue_cxx on MRI, java.util.PriorityQueue on jRuby.
|
# ? Jul 29, 2014 21:10 |
|
Hello friends, I work on a very large, old (for rails) codebase. My team has inherited a large section of code and none of us really understand it. Anyhow, I'm trying to write some tests using the existing factories, and they're a mess. I don't want to use them, but they need to remain in place because we have tons and tons of other tests currently relying on them. What is the best way to work around the existing factories without removing them? My options: 1) Settle for doing something like FactoryGirl.define(:class_new, class: class) with all my new factories 2) Refactor all the old factories/tests to use FactoryGirl.define(:class_old, class: class) Or something like: code:
4) Use FactoryGirl.modify to modify the classes as needed. I think this would just create more confusion. 5) Just live with what's there. 6) Don't use factory girl. Which of these is the least idiotic? I'm leaning towards number 2. DONT THREAD ON ME fucked around with this message at 00:31 on Jul 31, 2014 |
# ? Jul 31, 2014 00:29 |
|
#2 seems like it'd be the most maintainable. #3 seems to be the most clever, so that's something. e: option #7 and the one that will probably cause you the least heart-ache long run is refactor the factories through the complete code base. In other words, fix the factories and then fix broken tests.
|
# ? Jul 31, 2014 01:41 |
|
kayakyakr posted:e: option #7 and the one that will probably cause you the least heart-ache long run is refactor the factories through the complete code base. In other words, fix the factories and then fix broken tests. Yeah, that's the very long term goal. Ideally someday we'll move the tests over to using the new factories but who knows if that will ever happen. At least new tests will have maintainable factories to use.
|
# ? Jul 31, 2014 01:59 |
|
USSMICHELLEBACHMAN posted:Yeah, that's the very long term goal. Ideally someday we'll move the tests over to using the new factories but who knows if that will ever happen. At least new tests will have maintainable factories to use. A half migrated, old rails codebase is a huge pain in the rear end because it will never be fully migrated. You think the factories are bad now? Just wait. Been there, maintained that.
|
# ? Jul 31, 2014 02:29 |
|
Working on a MongoDB + Mongoid project and suddenly any Integer I store is of the unsigned type. Try to store -1, wind up with 4294967295. Anyone seen anything like this?
|
# ? Jul 31, 2014 04:20 |
|
In Rails 4, is there any way to apply scopes that is not the class methods? i.e. I have "Post" with the scope "published". Instead of Ruby code:
Ruby code:
|
# ? Jul 31, 2014 15:56 |
|
EVGA Longoria posted:In Rails 4, is there any way to apply scopes that is not the class methods? What do you actually want to do?
|
# ? Jul 31, 2014 16:21 |
|
Smol posted:What do you actually want to do? Trying to get rid of code duplication. We have helpers for our API Ruby code:
Ruby code:
Ruby code:
|
# ? Jul 31, 2014 16:45 |
|
EVGA Longoria posted:Trying to get rid of code duplication. We have helpers for our API I'd probably write that a bit differently. It's not a one liner, but easier to understand at a quick glance what's going on. Ruby code:
|
# ? Jul 31, 2014 17:08 |
|
kayakyakr posted:Working on a MongoDB + Mongoid project and suddenly any Integer I store is of the unsigned type. Try to store -1, wind up with 4294967295. Sounds like it's getting BSON'd (or de-BSON'd) as an unsigned type. Check whichever BSON gem you're using.
|
# ? Jul 31, 2014 17:15 |
|
Cocoa Crispies posted:Sounds like it's getting BSON'd (or de-BSON'd) as an unsigned type. Check whichever BSON gem you're using. using bson-ruby 2.3. this hasn't changed in some time. Suggestions on a different bson implementation?
|
# ? Jul 31, 2014 17:21 |
|
Thalagyrt posted:I'd probably write that a bit differently. It's not a one liner, but easier to understand at a quick glance what's going on. It's based on which endpoint they're using, /posts vs /posts/feed. Technically /posts is restricted for some things, but there's also a different in API representation and a few other things, so it's not as straightforward a authorization. I'm still fairly new to Rails stuff, would we incur much performance penalty for going from All to .published? My impulse was that we would.
|
# ? Jul 31, 2014 17:55 |
|
EVGA Longoria posted:It's based on which endpoint they're using, /posts vs /posts/feed. Technically /posts is restricted for some things, but there's also a different in API representation and a few other things, so it's not as straightforward a authorization. When I want to get ARQI started and want just a blank, get everything query, I like to do something like: Ruby code:
|
# ? Jul 31, 2014 18:19 |
|
EVGA Longoria posted:It's based on which endpoint they're using, /posts vs /posts/feed. Technically /posts is restricted for some things, but there's also a different in API representation and a few other things, so it's not as straightforward a authorization. Nope. Post.all.published and Post.published are nearly equivalent from a runtime perspective. Post.all simply returns a scope of all items which can be scoped further. Scopes aren't actually evaluated until you iterate over them (well, or a few other actions that necessitate making an actual SQL query). What they are is more like a set of parameters for a query that can be evaluated when needed to return a set of objects. In a lot of cases in Rails, that doesn't actually happen until you're displaying the returned records in a view.
|
# ? Jul 31, 2014 18:37 |
|
Thalagyrt posted:Nope. Post.all.published and Post.published are nearly equivalent from a runtime perspective. Post.all simply returns a scope of all items which can be scoped further. Scopes aren't actually evaluated until you iterate over them (well, or a few other actions that necessitate making an actual SQL query). What they are is more like a set of parameters for a query that can be evaluated when needed to return a set of objects. In a lot of cases in Rails, that doesn't actually happen until you're displaying the returned records in a view. kayakyakr posted:When I want to get ARQI started and want just a blank, get everything query, I like to do something like: Beautiful. Thanks guys, I'm going to work on this and clean it up a bit then.
|
# ? Jul 31, 2014 18:54 |
|
We have a Ruby on Rails app that uses Devise for logging in and out. I'm responsible for a backend XML API. Currently, users can use cURL commands to log in, update data, etc. I now need to enable an explicit logout capabitlity through the API, and I'm having trouble making it work. Every page of the UI has a logout link, and I just want to use cULR to simulate clicking that link. The logout sends a DELETE command to /users/sign_out, with an authenticity_token parameter. I've tried doing that with cURL, but I can't make it work. I've tried attaching the login cookie, and that didn't help. Do I need to get that authenticity token into the command data? If so, how do I do that? Would it be easier to make a new controller action and route to handle the POST/DELETE/whatever in code, so the user can just specify a URL?
|
# ? Jul 31, 2014 19:27 |
|
Peristalsis posted:We have a Ruby on Rails app that uses Devise for logging in and out. I'm responsible for a backend XML API. Currently, users can use cURL commands to log in, update data, etc. I now need to enable an explicit logout capabitlity through the API, and I'm having trouble making it work. Every page of the UI has a logout link, and I just want to use cULR to simulate clicking that link. Disable authenticity token for xhr calls. It makes no sense.
|
# ? Jul 31, 2014 21:22 |
|
kayakyakr posted:Disable authenticity token for xhr calls. It makes no sense. I don't understand this response. I'm just looking for a command to log out via cURL. The authenticity token already isn't being checked in the controller that handles the API XML inputs, but right now I'm just trying to mimic what the logout link does (i.e. it doesn't use my code, it goes through the Devise stuff). Peristalsis fucked around with this message at 21:30 on Jul 31, 2014 |
# ? Jul 31, 2014 21:27 |
|
This isn't a Rails-specific question, but: I've been having trouble switching from a default layout.erb file to an equivalent layout.haml file in Middleman. I want to use HAML for my layouts since I'm trying to become familiar with it, so I decided to replace the default layout with a HAML version. Unfortunately, when I replace layout.erb with layout.haml, I get this error:code:
code:
code:
So, I suspect that Middleman just won't accept anything except ERb for layout files. I can't find a single thing about this in the documentation, though, and I've even seen examples that all have layout.haml files that work perfectly fine. Is mine just different? Is there a flag I need to set with middleman init in order to use HAML files for layouts? What's going on?
|
# ? Aug 4, 2014 00:04 |
|
I'm not sure if this would fix your problem, but in my experience with Middleman I've always had to write layout files with a .html file extension before the .haml extension. So instead of layout.haml I would have layout.html.haml.
|
# ? Aug 4, 2014 08:13 |
|
Turns out it's because I wasn't restarting the server whenever I changed layouts. Whoops. Thanks for the help, though, doing that clued me in to the real problem.
|
# ? Aug 4, 2014 13:12 |
|
I'm trying to get back into using Rails, but I'm having a real issue getting SECRET_KEY_BASE to work with Rails 4. I'm using rbenv and I've installed rbenv-vars. I have an ~/.rbenv/vars file with SECRET_KEY_BASE=etc, and when I run 'rbenv vars' it comes up with: code:
The /config/secrets.yml file contains: code:
Is there another step I need to get this working? If it makes a difference I'm running Passenger through nginx. Thanks!
|
# ? Aug 8, 2014 12:06 |
|
secrets.yml is intended to be a configuration file that you keep locally and do not check in to your git repository. Theoretically, you'd keep a production version on your deployed server. So, you are seeing this issue in development or production? Now for certain deployments (like heroku), that won't work and you do need to use ENV variables. My suggestion then would be use use the figaro gem which sets environment variables in a much more repeatable manner than .rbenv/vars.
|
# ? Aug 8, 2014 15:52 |
|
kayakyakr posted:secrets.yml is intended to be a configuration file that you keep locally and do not check in to your git repository. Theoretically, you'd keep a production version on your deployed server. Not quite; the new world order is to check these files into source control and use environment variables for production config everywhere, not just in Heroku. That's why the secrets.yml Rails 4 ships with has the erb bit. See http://12factor.net/config Dirigible: there's nothing more you should have to do, so I'd suggest investigating your production setup to make sure the environment variables are available under the user your app runs as, not just you. If it's development mode, this shouldn't matter at all as there should be a static secret for development.
|
# ? Aug 8, 2014 16:40 |
|
Arachnamus posted:Not quite; the new world order is to check these files into source control and use environment variables for production config everywhere, not just in Heroku. That's why the secrets.yml Rails 4 ships with has the erb bit. See http://12factor.net/config Ah, so gems like figaro still have quite a bit of value.
|
# ? Aug 8, 2014 18:13 |
|
kayakyakr posted:Ah, so gems like figaro still have quite a bit of value. Yeah, so far I've mostly seen hand-rolled solutions which tend towards the crap (including mine). Edit: In fact they reference the 12 factor app thing in their README.
|
# ? Aug 8, 2014 18:29 |
|
kayakyakr posted:Ah, so gems like figaro still have quite a bit of value. We use dotenv which reads a .env file if it exists. It works out really well, as we use foreman to export our Procfile for the init system which can handle .env files (either when invoking foreman directly, or using its export functionality). .env files are also valid shell files, so you can use source to pull in any environment variables if you need them.
|
# ? Aug 8, 2014 18:32 |
|
necrotic posted:We use dotenv which reads a .env file if it exists. It works out really well, as we use foreman to export our Procfile for the init system which can handle .env files (either when invoking foreman directly, or using its export functionality). I did have to do a chown www-data:www-data on the file for it to work, though, so I suspect rbenv-vars would have also worked, per Arachnamus' post. I might give that a shot later, but I'm happy with how it works now.
|
# ? Aug 9, 2014 02:33 |
|
Just wrote up a blog post about how I handle authorization in my business's client portal. Figure you guys might be interested. Spoiler: It's neither CanCan nor Pundit. https://www.vnucleus.com/blog/2014/8/15/18-solving-complex-authorization-requirements-with-scopes
|
# ? Aug 15, 2014 03:19 |
|
I'm working on a hobby CRUD project that allows users to upload stuff and then view their submissions. Instead of the typical "/resources/:id" path, where id is the primary key, I'm thinking about creating a random url-safe base 64 string and associating it with each record. My challenge: I don't want to store these strings as part of the record. I would like the lookups to still be done using the primary key. Can I use something like Redis for this? I was thinking of a structure like { string => id } whereby during every request I feed it the string (which is the request param), find the corresponding id, and then use that id to find and display the record.
|
# ? Aug 16, 2014 18:53 |
|
enraged_camel posted:I'm working on a hobby CRUD project that allows users to upload stuff and then view their submissions. What's the use case?
|
# ? Aug 16, 2014 19:00 |
|
enraged_camel posted:I'm working on a hobby CRUD project that allows users to upload stuff and then view their submissions. That would work, yes, but like Smol in curious what the use case is here. Why don't you want that slug in your database?
|
# ? Aug 16, 2014 19:13 |
|
|
# ? May 8, 2024 16:33 |
|
enraged_camel posted:I'm working on a hobby CRUD project that allows users to upload stuff and then view their submissions. I would make that part of your current database. No reason to add additional complexity of bringing in another 3rd party application in a hobby app. Take a look at Friendly ID as another option.
|
# ? Aug 16, 2014 19:16 |