|
I have a large when/case switch in a library method. I'd like to be able to have this when statement take on extra case clauses. I tried doing it with a yield/block but it complains that my when is messed up. ExampleRuby code:
Ruby code:
KoRMaK fucked around with this message at 15:43 on Oct 1, 2014 |
# ? Oct 1, 2014 15:39 |
|
|
# ? May 28, 2024 15:01 |
|
Ruby code:
|
# ? Oct 1, 2014 15:55 |
|
Smol posted:
But what If I have a more than one when? I don't think it will work. In the meantime, I created a bunch of procs in a hash and another hash with the cases and the proc hash key as a value and it's working pretty well.
|
# ? Oct 1, 2014 16:14 |
|
KoRMaK posted:Oh... Ohhhhh. You're not going to be able to do that. Wrap the method: code:
|
# ? Oct 1, 2014 23:12 |
|
I'm using devise and want to set a custom password for a user. How do I do that? There is no password field, only encrypted_password. So I suppose I need to route my plain password through whatever hashing Devise uses and store that as the result in encrypted_password. Is there a Devise functionality that offers this, or how do I find out what the hashing algorithm is? e: Oh, I'm a dope. You just set the password and confirmation password fields and then do a save on the user object. Side question: how does inputting a password on a form get transmitted to the server? Is there js run on the client side that hashes the password before it sends? KoRMaK fucked around with this message at 21:35 on Oct 2, 2014 |
# ? Oct 2, 2014 21:27 |
|
KoRMaK posted:I'm using devise and want to set a custom password for a user. How do I do that? There is no password field, only encrypted_password. So I suppose I need to route my plain password through whatever hashing Devise uses and store that as the result in encrypted_password. Is there a Devise functionality that offers this, or how do I find out what the hashing algorithm is? not sure about your main question but to answer your side question a password field acts like just any input field... it's sent without any type of encryption to the server. The hash/salt comes from the server-side code afterward.
|
# ? Oct 2, 2014 21:35 |
|
xenilk posted:not sure about your main question but to answer your side question a password field acts like just any input field... it's sent without any type of encryption to the server. The hash/salt comes from the server-side code afterward.
|
# ? Oct 2, 2014 21:36 |
|
KoRMaK posted:So SSL does all the important stuff of keeping the text of the password from being intercepted as its submitted over a network? yes indeed. And you don't need to set password confirmation when you're setting a password in console, just update password.
|
# ? Oct 2, 2014 22:15 |
|
How do I get procs to run in the context that they are being called from, instead of the context they were written from?Ruby code:
|
# ? Oct 3, 2014 21:22 |
|
KoRMaK posted:How do I get procs to run in the context that they are being called from, instead of the context they were written from? That is not how closures work. If you want to pass a variable to a proc at run time then pass it as an argument to `call`, and it'll show up as a block variable in the proc.
|
# ? Oct 3, 2014 21:40 |
|
Arachnamus posted:That is not how closures work. If you want to pass a variable to a proc at run time then pass it as an argument to `call`, and it'll show up as a block variable in the proc. Oh geez, thats so many variables. I was hoping the proc would get executed in the context of where it was being called from. e: I have a bunch of procs that will take the same parameters. Can I write a class that extends proc? I'd like to just take a block, and then when I call it pass in the params. So I'd like to make a new class that prevents me from having to declare the variables each time Ruby code:
Ruby code:
KoRMaK fucked around with this message at 22:58 on Oct 3, 2014 |
# ? Oct 3, 2014 22:16 |
|
KoRMaK posted:How do I get procs to run in the context that they are being called from, instead of the context they were written from? Ruby code:
Sil fucked around with this message at 01:26 on Oct 4, 2014 |
# ? Oct 4, 2014 01:24 |
|
Sil posted:
undefined local variable or method `my_var' for #<Klass2:0xfd3fc70> KoRMaK fucked around with this message at 03:36 on Oct 4, 2014 |
# ? Oct 4, 2014 03:23 |
|
KoRMaK posted:Oh geez, thats so many variables. I was hoping the proc would get executed in the context of where it was being called from. I vaguely remember a few weeks back saying to you that you're going to reach a point where you get lost in the metaprogramming and everything starts to become incomprehensible. This is one of those points. What are you actually trying to achieve?
|
# ? Oct 4, 2014 09:16 |
|
I have a bunch of procs that I would like to have executed in the context that they are called from so they have access to the local variables near them. They will be getting called from inside a loop, and that loops variables' values will change each iteration.
|
# ? Oct 4, 2014 16:03 |
|
Just don't do that. Dynamic scoping is straight from hell.
|
# ? Oct 4, 2014 16:12 |
|
much easier: pass an options hash to those functions that you are calling as an argument. Use the options hash inside the function.
|
# ? Oct 4, 2014 16:15 |
|
kayakyakr posted:much easier: pass an options hash to those functions that you are calling as an argument. Use the options hash inside the function. .... Booooo I have a bunch of these things that I'm going to have to add block parameters too now. Dang. Sounds like the sanest approach though.
|
# ? Oct 4, 2014 16:23 |
|
KoRMaK posted:That doesn't work. Am I missing something? I think I'd have to turn my_var into @my_var for this to work. I was hoping to get the nearest scoped variables from where it was ran, not where it was created. That is, I want the context to be where its run, not from where it was created. You're a wild dude. Ruby code:
Maybe this can help you achieve what you want http://djellemah.com/blog/2013/10/09/instance-eval-with-access-to-outside-scope/ ? It's too saturday for me to fully understand what he's writing about, frankly, but it seems vaguely related.
|
# ? Oct 4, 2014 20:27 |
|
Is there a particular convention when generating controllers? Way I understand it is that the basic format is rails g controller ControllerName action1 action2. Is that right? And what sorts of things need a controller? It makes sense for a controller to be called User and have actions create and delete, but what would a controller for static pages do? What other kinds of things would necessitate a controller?
|
# ? Oct 7, 2014 14:43 |
|
Pollyanna posted:Is there a particular convention when generating controllers? Way I understand it is that the basic format is rails g controller ControllerName action1 action2. Is that right? And what sorts of things need a controller? It makes sense for a controller to be called User and have actions create and delete, but what would a controller for static pages do? What other kinds of things would necessitate a controller? So if you want to get a feel for controller convention, you should generate a few scaffolds instead. Scaffold will generate the model, controller, views, and everything else. It'll come with very basic features. Rails controllers tend to be resourceful. that means that they're intended to plug in to the route like so: Ruby code:
Generally, you want your controller to be plural, unless you're dealing with a singleton type of object. So User might be one that isn't plural. A resourceful route will have index, show, new, create, edit, update, destroy. You may not need all of those, but that's your starting set.
|
# ? Oct 7, 2014 16:00 |
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
|
|
# ? Oct 9, 2014 18:57 |
|
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 |
necrotic posted: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: Nope just the ri/rdoc versions, here's some ncdu output: code:
code:
fletcher fucked around with this message at 23:44 on Oct 9, 2014 |
|
# ? Oct 9, 2014 22:29 |
|
necrotic posted:
Preferably --no-document today unless you're rocking an extremely old version of Rubygems for legacy applications. --no-ri --no-rdoc has been deprecated since ~2.0 and will (eventually) be going away.
|
# ? Oct 9, 2014 23:53 |
|
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:Is there a particular convention when generating controllers? Way I understand it is that the basic format is rails g controller ControllerName action1 action2. Is that right? And what sorts of things need a controller? It makes sense for a controller to be called User and have actions create and delete, but what would a controller for static pages do? What other kinds of things would necessitate a controller? Think about it from the perspective of responsibility. Your views are responsible for presenting data in HTML form (or JSON, or..). Your models are responsible for executing actions on data like finding something, saving something, executing a state change, etc. Your controllers are responsible for orchestrating everything to get the user's request served appropriately. From that point of view, controllers handle the "what"; what a given request means, what to do if they're unauthenticated, what data to return to the user, while your views and models handle the how. How should I display this data, or how do I record the fact that this or that document is published. If you're following REST, the "what" is pretty well defined by REST itself, so follow the REST convention and you'll be fine. Not all requests are about resources as you've discovered, in which case the scope of your controller is up to you, you have to assign responsibility to that controller appropriately for what it's doing. In the case of a "static" controller, the "what" is typically just finding the right view to render and providing a few bits of generic data. As with all things Rails, you don't have to do things the Rails way, but it will fight you every step if you don't.
|
# ? Oct 10, 2014 13:09 |
|
I have a dashboard and some other pages that just have a route setup, and methods in the controller that gather the info needed and then the view is rendered. The conventions are there to stick to, to keep you on the 'rails', but you can deviate from them whenever, at your own benefit or peril, as you see fit. They are just suggestions for best practices.
|
# ? Oct 10, 2014 16:45 |
|
KoRMaK posted:I have a dashboard and some other pages that just have a route setup, and methods in the controller that gather the info needed and then the view is rendered. This. MVC is a powerful concept and worth using in a lot of CRUD cases. But it is not he be-all end-all that it looks at time. If your model consists entirely of static queries that just pull a report, it's not unreasonable to put that in a controller and have no model.
|
# ? Oct 11, 2014 21:58 |
|
EVGA Longoria posted:This. MVC is a powerful concept and worth using in a lot of CRUD cases. But it is not he be-all end-all that it looks at time. If your model consists entirely of static queries that just pull a report, it's not unreasonable to put that in a controller and have no model. You're right, though consideration should be given to testing and reuse. Rails controllers are very muddy, in that they like to mix their internals with views and a bunch of other rails mechanisms, making them harder and slower to unit test than models (activerecord or otherwise).
|
# ? Oct 11, 2014 23:50 |
|
The simplistic rails model also misses the service / actual business logic layer. Don't be a dummy and try to fit everything an app does into rails controllers or models. The dumber they both are (i.e. Controllers only respond to http requests, models pretty much just hold data), the better off your app will be in the long run.
Smol fucked around with this message at 08:07 on Oct 12, 2014 |
# ? Oct 12, 2014 08:04 |
|
Smol posted:The simplistic rails model also misses the service / actual business logic layer. Don't be a dummy and try to fit everything an app does into rails controllers or models. The dumber they both are (i.e. Controllers only respond to http requests, models pretty much just hold data), the better off your app will be in the long run. I wish there were more resources out there that explained this, because it's very true. The Rails model works for simple applications, but once you get beyond simple it falls apart. My models in the vNucleus portal have plenty of logic on them since it's a pretty complex application, but that logic is entirely data consistency/manipulation logic, not business logic. The meat of the application is all factored out into separate classes that encapsulate that operation, making extensive use of Wisper for services that controllers consume, ActiveModel::Model based form objects for any complex action that takes data in, and plain old service classes with an interface that makes sense for the service for other units of logic. It really does make maintaining the application much easier in the long run! It's also extremely easy to test due to the way the logic has been factored out. I've got about 1500 tests and 96% coverage at present.
|
# ? Oct 12, 2014 17:29 |
|
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...?
|
# ? Oct 12, 2014 21:40 |
|
I'd put it on the model.
|
# ? Oct 12, 2014 22:11 |
|
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 |
|
I love working with Rails but I feel like a fraud, using gems for everything. Should I try rolling my own functionality for lots of things rather than just installing a bunch of gems if I ever want to land a Rails dev job?
|
# ? Oct 15, 2014 16:26 |
|
Dystram posted:I love working with Rails but I feel like a fraud, using gems for everything. The opposite: the more gems you know how to use and are familiar with the quicker you can one man army an app. It's the best part of rails, you just pluck libraries you need that would normally take a while in itself to develop, test and maintain.
|
# ? Oct 15, 2014 16:28 |
|
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?
|
# ? Oct 15, 2014 16:39 |
|
KoRMaK posted:The opposite: the more gems you know how to use and are familiar with the quicker you can one man army an app. It's the best part of rails, you just pluck libraries you need that would normally take a while in itself to develop, test and maintain. Good to know. Thanks!
|
# ? Oct 15, 2014 16:41 |
|
|
# ? May 28, 2024 15:01 |
|
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? Yeah, it's good to know how to do it. https://www.railstutorial.org/book has a few chapters dedicated to it.
|
# ? Oct 15, 2014 16:42 |