|
prom candy posted:Are you sure your cellar method is saving the user_id? Try rewriting your code like this. Note that I got rid of that nasty condition for you cellar! is invoked from a user object. Namely current_user.cellar! The idea would be to have a link on a beer page when a user is signed in. This will give user (signed in user) and beer (beer page viewing), and the form will give the option of year, size, and quantity.
|
# ? Jun 11, 2013 18:18 |
|
|
# ? May 15, 2024 03:38 |
|
I'd just like to say that that method name really shouldn't have a bang on it.
Smol fucked around with this message at 21:25 on Jun 11, 2013 |
# ? Jun 11, 2013 21:03 |
|
I tend to add bangs to methods that write to the database, which probably isn't correct.
|
# ? Jun 11, 2013 21:22 |
|
It doesn't help that there are multiple definitions. Most of the Ruby core/standard library treats it as an indicator that the method will not return anything and will modify its calling object directly. Rails tends to use it to designate that failure should raise an exception (at least in ActiveModel's viewpoint).
|
# ? Jun 11, 2013 21:27 |
|
Bangs should be used when you have two variants of some operation, one "dangerous" and the other "safe". In the most common case, the dangerous variant modifies the receiver directly and the safe on returns a new copy (example: String#gsub! and String#gsub). In ActiveRecord operations, the dangerous variant may raise an exception while the safe will not (e.g. ActiveRecord::Base.save! and ActiveRecord::Base.save).
|
# ? Jun 11, 2013 21:29 |
|
Is there a good way to indicate that a method will not just change an instance's attribute but also save it?
|
# ? Jun 12, 2013 04:27 |
|
prom candy posted:Is there a good way to indicate that a method will not just change an instance's attribute but also save it? I use the bang for that.
|
# ? Jun 12, 2013 06:50 |
|
Cocoa Crispies posted:I use the bang for that. So do I but now I'm being told that's wrong.
|
# ? Jun 12, 2013 18:21 |
|
How would I dynamically add an after filter based on the conditional of whether an instance method exists? I am making a module that attachs to controllers and I want to add an after filter to a method only If said method exists
|
# ? Jun 12, 2013 18:44 |
|
KoRMaK posted:How would I dynamically add an after filter based on the conditional of whether an instance method exists? Maybe something like: code:
|
# ? Jun 12, 2013 18:51 |
|
I would think that should work, but the class doesn't have the method in its class methods at te time the module gets run. So it's like the method doesn't exist for me to put a filter on.
KoRMaK fucked around with this message at 19:22 on Jun 12, 2013 |
# ? Jun 12, 2013 19:19 |
|
prom candy posted:So do I but now I'm being told that's wrong. If nobody actually working on the project has a problem with it then use it. When I have model methods that make changes like that, I give 'em an exclamation point to denote that they're exciting.
|
# ? Jun 12, 2013 19:30 |
|
KoRMaK posted:How would I dynamically add an after filter based on the conditional of whether an instance method exists? Why?
|
# ? Jun 12, 2013 19:31 |
|
Why not? It will be better this way than editing 30 files to conform. KoRMaK fucked around with this message at 19:37 on Jun 12, 2013 |
# ? Jun 12, 2013 19:33 |
|
KoRMaK posted:Why not? Because it's turning out to be difficult? You might see if making the Module into an ActiveSupport::Concern would help, or you might describe what the end goal is (see https://en.wikipedia.org/wiki/5_Whys ) so we can figure out if there's a more generally accepted way to do what you want.
|
# ? Jun 12, 2013 19:37 |
|
C'mon Don't logic some sense into me. I sill think it be useful to add filters from a module. Wait, adding a filter on that function inside the controller doesn't work either. I should go read up on filters. E: wtf filters only get run on the methods that are called during routing? I added my before filter to edit, instea of a function that gets called by edit, and it started to work. I guess I had a fundamental misunderstanding of when filters are run. KoRMaK fucked around with this message at 23:06 on Jun 12, 2013 |
# ? Jun 12, 2013 19:47 |
|
I wanna make rubygems use ruby 2.0.0 Here's the output to gem env: code:
|
# ? Jun 13, 2013 00:48 |
|
You're using Ruby 1.8 provided by your operating system. Install ruby 2.0 with rbenv & ruby-build or rvm or similar.
|
# ? Jun 13, 2013 01:50 |
|
raej posted:cellar! is invoked from a user object. Namely current_user.cellar! The idea would be to have a link on a beer page when a user is signed in. This will give user (signed in user) and beer (beer page viewing), and the form will give the option of year, size, and quantity. Right, what I'm saying is maybe it shouldn't be. Maybe the user class shouldn't be responsible for this particular action. http://en.wikipedia.org/wiki/Single_responsibility_principle
|
# ? Jun 13, 2013 02:44 |
|
prom candy posted:Right, what I'm saying is maybe it shouldn't be. Maybe the user class shouldn't be responsible for this particular action. http://en.wikipedia.org/wiki/Single_responsibility_principle Maybe I need to step back and get an idea of the Ruby way to accomplish the task I want to accomplish. Users have many beers through cellared_beers (A person can cellar many different kinds of beers) Beers have many users through cellared_beers (A particular beer can be cellared by many different users) Cellared_beers has extra attributes that describe the physical bottle in a user's cellar (year, size) A Beer page displays info on a particular beer (Brewery, description, ABV, etc). If a person is logged in, there should be a button to add the beer to the current_user's cellar. This will ask for year and size, as well as quantity. If a cellared_beer matches for the current_user for that beer with the same year and size, add quantity to that cellared_beer's existing quantity (Bought a 6 pack of 2013 12oz bottles, then bought another 6-pack of 2013 12oz bottles) If cellared_beer does not match on all three attributes, create cellared_beer with that quantity. I think I am trying to over complicate this.
|
# ? Jun 13, 2013 03:29 |
|
raej posted:Maybe I need to step back and get an idea of the Ruby way to accomplish the task I want to accomplish. What they're trying to say is that cellar! is not a particularly good method for a User to have. If it were me, I'd be doing something like this: Ruby code:
This is completely off-the-cuff and I may have had a few beers. The Journey Fraternity fucked around with this message at 05:04 on Jun 13, 2013 |
# ? Jun 13, 2013 05:02 |
|
The Journey Fraternity posted:This is completely off-the-cuff and I may have had a few beers. Where did you get the beer from?
|
# ? Jun 13, 2013 05:38 |
|
Is there an editor or eclipse plugin that will open the other 2 files of a ror object when I open 1? I want to open the beer form view and have the model and controller open in editor windows for it automatically. I am now in the realm of shaving off repetitive tasks that take seconds because of their cost over a career-time. And I am lazy. I mean efficient.
|
# ? Jun 13, 2013 14:44 |
|
KoRMaK posted:Is there an editor or eclipse plugin that will open the other 2 files of a ror object when I open 1? It's not "ror" unless you're a recruiter, it's "Rails." Objects only usually have one file. Just because the scaffold generator makes files with similar names doesn't mean they have to be related. Don't bother microoptimizing your workflow when you barely know what's going on; it'll save seconds but cost hours.
|
# ? Jun 13, 2013 17:19 |
|
The Journey Fraternity posted:What they're trying to say is that cellar! is not a particularly good method for a User to have. If it were me, I'd be doing something like this: So on the beer view, have a form_for add_to_cellar and pass in current_user.id and beer.id (from the page), and size, year, quantity from the form?
|
# ? Jun 13, 2013 17:46 |
|
Pass beer.id, size, year and quantity to a form. Grab the user id from the session.
|
# ? Jun 13, 2013 17:56 |
|
Cocoa Crispies posted:It's not "ror" unless you're a recruiter, it's "Rails." Objects only usually have one file. Just because the scaffold generator makes files with similar names doesn't mean they have to be related. Rails object in my post meant a rails scaffolded set of views a controller and a model centered around one name working in conjunction with each other. I'd still want the option for the model and controller to open up when I open a view when appropriate. KoRMaK fucked around with this message at 18:02 on Jun 13, 2013 |
# ? Jun 13, 2013 18:00 |
|
Split views and an IDE like Rubymine (highly recommended, it's well worth the price) allow you to do that easily. Alternatively, you could use something like rails.vim for vim or rinari for emacs.
|
# ? Jun 13, 2013 21:37 |
|
Cocoa Crispies posted:It's not "ror" unless you're a recruiter, it's "Rails." Objects only usually have one file. Just because the scaffold generator makes files with similar names doesn't mean they have to be related. For me, it's definitely the largest minor annoyance in working with rails, and it's a totally legitimate thing to ask about. Rails' file structure, while logical, is pretty frustrating to navigate. Usually by the time I scroll through my views, I've forgotten what I'm looking for. quote:Just because the scaffold generator makes files with similar names doesn't mean they have to be related. This is absurd.I didn't use the scaffold generator when I was starting out, but I still gave things similar names and put them in similar folders and obeyed the MVC, because it literally wouldn't work otherwise. Rails is built around the MVC and it places a huge emphasis on convention. If you give your controllers and models different names, you're going to make things hard on yourself. If you put files in the wrong folder, you're going to make it hard on yourself. Just because you can get around the convention, that doesn't you don't "get" ror unless you put everything in non standard locations. It's called Ruby on Rails for chrissake. That said, I don't have an answer to the question. I tried creating a folder of symlinks outside my rails directory, and those folders grouped related models/controllers/views. But it was too much of a hassle to deal with.
|
# ? Jun 13, 2013 22:49 |
|
Sublime Text 2 along with Cmd/Ctrl-T file searching and a couple plugins for quickly creating new files and folders is a pretty good environment.
|
# ? Jun 13, 2013 23:20 |
|
Smol posted:an IDE like Rubymine (highly recommended, it's well worth the price) Counterpoint: If you type fast and/or are used to the responsiveness of editors like Sublime Text, Rubymine will feel like you are using VNC or something. This kills my flow, but YMMV.
|
# ? Jun 14, 2013 20:59 |
|
If Your Business Uses Rails 2.3 You Need To Move To A Supported Option ASAP TIL there was a vendor providing long-term support versions of Rails updates. I also like the 10 day lag between paid and free updates. Are you feeling lucky you won't get owned inside of 10 days when an exploit gets released?
|
# ? Jun 17, 2013 20:52 |
|
going to be teaching some people ruby/rails, any recommended resources? I've found: - http://curriculum.railsbridge.org/curriculum/ - http://tutorials.jumpstartlab.com/
|
# ? Jun 20, 2013 21:57 |
|
I've been using RailsTutorial.org's online book as my learning tool.
|
# ? Jun 20, 2013 22:08 |
|
Check out http://www.codelearn.org/rails-tutorials It lets you learn basic rails without having to setup a dev environment locally.
|
# ? Jun 20, 2013 22:11 |
|
wolffenstein posted:I've been using RailsTutorial.org's online book as my learning tool. Awesome thanks, totally forgot about that book! wolffenstein posted:I've been using RailsTutorial.org's online book as my learning tool. Oh that's neat, but I think I want students to actually set up and use a development environment. Luckily we're setting up an install fest to help students with that the day before the class, but that's something I can probably point them to after the class for them to try.
|
# ? Jun 20, 2013 22:43 |
|
soullessshoe posted:Oh that's neat, but I think I want students to actually set up and use a development environment. Luckily we're setting up an install fest to help students with that the day before the class, but that's something I can probably point them to after the class for them to try. Set up a VM and how them how to use Vagrant.
|
# ? Jun 20, 2013 22:49 |
|
I was just going to recommend vagrant as well. Having a standardized environment for students and instructor could potentially save you a lot of pain.
|
# ? Jun 20, 2013 22:59 |
|
haha nice, I am actually testing some vagrant stuff right now to set up an environment for windows folks, though I'll probably ask everyone to go that route.
|
# ? Jun 20, 2013 23:28 |
|
|
# ? May 15, 2024 03:38 |
|
soullessshoe posted:going to be teaching some people ruby/rails, any recommended resources? I did this with non-programmers.
Good luck!
|
# ? Jun 21, 2013 16:04 |