|
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 |
|
|
# ¿ Apr 27, 2024 07:30 |
|
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: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 |
|
Pollyanna posted:Using send in an instance method doesn't seem to work, cause it seems to think that the method being called is a method on the Class, instead of a method on the main application. Do I have to pass the method itself in, somehow? Option 3 (which is slightly different from kayakyakr's Option 2) is to use Object#method to get an instance of the Method: Ruby code:
|
# ¿ Sep 29, 2014 15:41 |
|
fletcher posted:Why does /var/lib/gems/1.9.1/doc/fog-1.23.0 take up 660MB? I have a couple different versions in there too, taking up tons of space Fog is thoroughly documented and supports a ton of services. You often don't need the docs locally (thanks to rdoc.info), and I recommend creating a ~/.gemrc or /etc/gemrc with the following: code:
|
# ¿ Oct 9, 2014 19:35 |
|
Molten Llama posted:Preferably --no-document today unless you're rocking an extremely old version of Rubygems for legacy applications. I did not know this! Time to update my rc file and change what I tell everyone at work.
|
# ¿ Oct 10, 2014 00:08 |
|
Pollyanna posted:Huh. That answers a lot of my questions, actually. I was always confused by Rails' "models only data, controllers only processing/logic" dealio. I'm trying to make a model output its characteristics in a particular order now, and I'm having trouble figuring out whether to do that in the Model, Controller, or View. I want to say the Model, going by rspec-rails documentation, but apparently not...? In terms of output for an API? Use jbuilder views for that.
|
# ¿ Oct 12, 2014 23:38 |
|
Doh004 posted:I'm just slowly working my way through my first rails application and just rolled my own user authentication. I know there's tons of gems out there that do this already though... but it's a good learning experience, right? It is good knowledge, but after you've done it once start using Devise. Its amazingly powerful and really quick to get all of the functionality you need for authentication (including pluggable schemes, like oAuth and 2FA). Authorization is a different beast. I used to recommend CanCan, but its been discontinued (although the community has picked it up with CanCanCan). I've started using Pundit, which is basically helpers for writing authorization rules inside of POROs, and I have been loving it. It's a bit more verbose, but makes testing and understanding the system so much easier.
|
# ¿ Oct 15, 2014 18:00 |
|
Thalagyrt posted:I honestly disagree on using Devise for everything. We've rolled our own authentication in-house and couldn't be happier. Devise didn't do what I wanted - it got me 95% of the way to where I wanted to be, then I spent more time than it took to roll my own authentication wrangling Devise to sort of kind of maybe do what I wanted. I ended up ripping almost all of devise's built in functionality out, then realized I may as well roll my own. It meets a specific, and admittedly common, use case, but if you're not in that exact use case it falls apart spectacularly. This is the case with the majority of gems that try to be a solution for everyone like that. This is true for any language and any set of 3rd party libraries: they work for the most common cases, but once you need something specialized (I would be interested in what use case you had that didn't fit) rolling your own is generally the best approach. quote:Pundit's no exception to this one-size-fits-all problem. Pundit assumes that authorization is going to be based on roles on the user, and the second you want to bring a secondary object (user has x permissions on account y and z permissions on account q, for example) into the authorization scope, Pundit falls apart without extensive modification. The whole concept of doing authorization in functions that take two objects is kind of silly anyway. Why should you have both a function to check if a user has rights on an object as well as a scope to return only the objects the user has rights to? Simply use the scope all the time. Check out Consul for an example of that. It's far more flexible than Pundit and can handle extremely bizarre authorization requirements very elegantly. I had not heard of Consul and will check it out. I do like the idea of scope-centric authorization.
|
# ¿ Oct 15, 2014 19:27 |
|
Thalagyrt posted:Henning (the author) has a great talk about Consul if you want to watch it! Excellent, thanks!
|
# ¿ Oct 15, 2014 20:01 |
|
The Milkman posted:I don't suppose there's a way to have basic http auth always reprompt for credentials? Not a built-in way. You can hack it by redirecting them to a URL with a bogus username, but its not very friendly.
|
# ¿ Oct 29, 2014 03:33 |
|
code:
That will print out a json encoded version of the object, which can go directly into your javascript block.
|
# ¿ Nov 6, 2014 23:55 |
|
Pollyanna posted:We're being taught differently, as we use Rails as an API server (database, AJAX, etc.) and don't bother to use the asset pipeline or Javascript libraries since it's headless. Instead, we create separate front-end static asset servers that hand out HTML, CSS and JS to the client which then access the API server to render everything. Is this common? We're doing this now at work. Our monorail, which contains the old dashboard and all of our business logic, now exposes an api that a separate project speaks to. The assets are served up through the monorail in the end (well, a cdn, but the view lives in the monorail), but we are eventually moving that away too.
|
# ¿ Nov 7, 2014 17:42 |
|
kayakyakr posted:This also sorta makes sense if you haven't required your factory files in some form or fashion. Yeah, do you have the factory_girl_rails gem? It handles loading factories automatically. It looks like you do based on the use of generators. I've never had this problem myself. Maybe something weird with your bundle file and test not finding factory_girl_rails?
|
# ¿ Nov 10, 2014 22:47 |
|
Pollyanna posted:I forgot to add require 'rails_helper' to my spec files. Yeah that'll do it. Glad it was a dumb mistake and not some arcane issue with gem deps!
|
# ¿ Nov 11, 2014 03:03 |
|
Peristalsis posted:I'm sure this is heresy or something, but is RSpec really that much better than the built in testing suite? I found a quick introduction to it in one of the books I read (Eloquent Ruby, maybe?), very poor documentation and examples online, and I just didn't see how it was fundamentally better than the unit tests and fixtures. Are there tests I can do in RSpec that I can't do with the built-in testing framework, or is it just supposed to be more slick and fashionable? RSpec doesn't let you do more than the core Test framework, but it is far more expressive. If you're doing BDD/TDD its a much stronger tool as you can literally describe your code before your write it out. Then you write the code and it all works. You can probably do it successfully with Test, and really it boils down to personal preference. I can use either, but if I am doing TDD I vastly prefer rspec.
|
# ¿ Nov 21, 2014 17:13 |
|
Smol posted:Maintaining Extends to libraries as well.
|
# ¿ Nov 21, 2014 23:49 |
|
kayakyakr posted:Concern is a fairly new, easy way to extend ActiveModel objects. It's a slightly cleaner method than the normal ruby include methodology. It's actually for anything really. There's app/concerns, app/models/concerns, and app/controllers/concerns. Its for functionality that is reusable across multiple objects (usually of a common type, like a model or controller) but not every object. Its kind of a band-aid around fat controllers and models in my opinion. Once you include them you still end up with a fat controller or model, its just hidden away in another module.
|
# ¿ Nov 25, 2014 18:43 |
|
xtal posted:Concerns increase modularity and composability, and that leads to better controllers and models and such. It doesn't prevent (or relate to) the problem of making objects that do too much. My point is that when you include them the controller/model is still fat, its just hidden. It also adds a pain point in figuring out "okay so Butt.new.make_a_fart works, but where is it defined? lets go see Butt! poo poo, its not there. Okay, which of these 10 modules is it in?". Yes, you can grep 'def make_a_fart', but its taken you more steps to end up finding where its defined than it ever should have. It also has a problem with method name collisions, which are (surprise) silent in Ruby and just take the most recent as truth. Hope you didn't accidentally override some rarely used but important method in your new module! (Yes, tests, because those always exist in the project you got hired to work on)
|
# ¿ Nov 26, 2014 01:55 |
|
Thalagyrt posted:Last month I was working on building an APN abstraction before having my coffee and thought "send would be a great method name to use for the method that sends an APN!" Whoops. I think this is why you're supposed to use __send for message passing since 1.9, but basically nobody does -_- MALE SHOEGAZE posted:I just skip straight to searching for def method. Of course that only works most of the time, thanks to metaprogramming magic. Yeah, me too. But it's a context switch I would much rather not be necessary.
|
# ¿ Nov 26, 2014 18:47 |
|
Basically:
Another nice thing about lets is composing your test data. A simple example would be a Ticket that moves through several states from new to resolved, with each state changing the behavior of the record slightly: code:
|
# ¿ Dec 3, 2014 02:18 |
|
Gmaz posted:Maybe I'm not getting something but I don't understand how this will help me with linking. I see two options:
The first option is more explicit, but requires you to use a new method for nearly all of your links. The second would be more "transparent", but could catch a new developer by surprise.
|
# ¿ Dec 10, 2014 20:37 |
|
Smol posted:Model attributes that are not marked as serializable (stuff that is saved as json or yaml strings in the database, usually arrays) are only saved when they are marked to be dirty, i.e. when you use the setter methods. If you mutate the values directly, Rails doesn't know about that. While I wouldn't recommend it for this use case, you can force an attribute to dirty by calling foo.prop_will_change!. See the API Docs for more on dirty attributes.
|
# ¿ Dec 12, 2014 18:53 |
|
xenilk posted:I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field. There's no "right" way to go about testing. RSpec is definitely popular, but I think Test::Unit holds its own in a large part of the field. I have heard less about minitest, but I know its also a relatively new player on the block.
|
# ¿ Dec 19, 2014 18:21 |
|
Doghouse posted:Does anyone know of a ruby reference resource I could use for the basics of Ruby, coming from a C#/Java background? I'm having trouble getting a handle on the basic syntax for an assignment. I'm trying to set up a hash as a class variable and I can't even figure out how. code:
|
# ¿ Jan 23, 2015 00:15 |
|
EVGA Longoria posted:That's an instance variable. A class variable would be @@hash. Then here: code:
code:
|
# ¿ Jan 23, 2015 18:15 |
|
MALE SHOEGAZE posted:What does this mean? CodeClimate grades your code from F to A based on some heuristics. With an A being the "best".
|
# ¿ Apr 3, 2015 17:51 |
|
Buckhead posted:I need to process a string word by word and see if certain words match a condition, then compile the string back together. Basically, I am pulling social media posts and want #s and @s to show up in blue. If you want to avoid using gsub, you could split and then join the string: Ruby code:
|
# ¿ Apr 6, 2015 17:00 |
|
Gmaz posted:That's nice, never realized this. Yeah, its implemented as a Hash underneath, so anything looking for a specific value just maps to a hash key.
|
# ¿ Apr 6, 2015 19:12 |
|
kayakyakr posted:you suck where's railsconf this year? ATL I should've gone considering its right around the corner. Oh well!
|
# ¿ Apr 21, 2015 13:52 |
|
Buckhead posted:I am being returned a hash from an API with two identical keys. I need to save the first and second value to separate variables. Looks like it will always be two values, so I'd just do this: Ruby code:
Also, there's Enumerator#each_with_index so you don't have to increment your own counter. necrotic fucked around with this message at 18:14 on Apr 21, 2015 |
# ¿ Apr 21, 2015 17:57 |
|
KoRMaK posted:e: Fixed it, changed some init settings and it started working. Wierd that it required me to exit the terminal though. I think it was fixed by remove config.reload_classes_only_on_change = false Yeah that setting will do it. And rails will only reload files from app/ and lib/, config/ file changes require a full reboot of the app. Not sure why you had to exit your terminal (I assume you mean like Terminal.app or iTerm2.app, not the rails console).
|
# ¿ Apr 24, 2015 14:27 |
|
KoRMaK posted:Thanks for the suggestions guys. Most queue systems give you a way to limit the number of workers, not a strict per/s limit. Once you figure out how long the task takes you can kind of limit the work per/s by lowering/raising the number of workers, but it won't be perfect. I'm not sure about Delayed Job or Resque, but our job system lets you change queue reading strategies which would let you create a strategy that throttles when receiving messages. This would limit you to one process with an option for multiple threads, though you could do multi-process support with some work.
|
# ¿ May 13, 2015 22:01 |
|
We use Chore, which we wrote internally and recently open sourced. Documentation is a little lacking, but the interface for the different types of strategies is pretty straight forward. We don't have anything that needs throttling internally so there's no mechanism built-in to handle it, but adding it to a custom Queue consumer wouldn't be all that difficult.
|
# ¿ May 14, 2015 19:01 |
|
kayakyakr posted:Reminder that ActiveJob was promoted to a first class citizen in the most recent Rails, so if you pick a gem to go with, you should probably pick one that integrates with activejob Yeah, we should make an adapter for chore. Not a priority for us as we're still on 3.x
|
# ¿ May 14, 2015 21:55 |
|
MasterSlowPoke posted:I'm just about to use Resque, is there anything I should know about it or should I jump to something else before I'm in too deep? Resque should be fine. I wouldn't use it at scale from past experiences, but if you go the ActiveJob route switching out backends is dead simple.
|
# ¿ May 14, 2015 22:11 |
|
KoRMaK posted:I don't get it. But I didn't get Rails either. Why is Crystal eye popping good? If you like Ruby but want an actual type system, I guess. I wish the homepage had more info, and that the manual wasn't split into a million small sections. Seriously, what the gently caress: http://crystal-lang.org/docs/syntax_and_semantics/comments.html
|
# ¿ May 20, 2015 19:37 |
|
The proper way to make sure your test database is correct is rake db:test:prepare. Not sure why it stopped happening on db:migrate for you, but use the test:prepare version instead.
|
# ¿ May 28, 2015 21:35 |
|
Peristalsis posted:If plain old command-line ssh has an option to suppress the additional password prompts, I guess I could just construct a command string to use with backticks in the ruby code, if I can't find a similar option in net-ssh. We've had to do similar things one or two other times with ruby features that were slower than their CLI counterparts. There is not a way to remove the prompt for password-based logins. The proper way to solve this situation is using key pairs, or possibly through an LDAP system.
|
# ¿ May 30, 2015 22:17 |
|
|
# ¿ Apr 27, 2024 07:30 |
|
KoRMaK posted:Yea I saw that, but it seems like not a good practice for some reason. I guess that my reason for feeling that way is that I don't see a reason to have more than 1 user be in charge of "rails" things. You may be able to get that by making an rvm-ro group and giving it readonly access to the RVM install.
|
# ¿ Jun 19, 2015 07:22 |