|
atastypie posted:Hobo is brand new, so there is very little up to date documentation let alone an entire book. You could print off the docs from the website and reference those instead. code:
vg8000 fucked around with this message at 13:26 on Aug 23, 2007 |
# ? Aug 23, 2007 02:33 |
|
|
# ? Apr 27, 2024 04:24 |
|
@author.books.sum(&:price) (Although I think it's functionally identical to the above example)
|
# ? Aug 23, 2007 15:33 |
|
You probably want to use :include to join in all the books when you fetch the author.
|
# ? Aug 23, 2007 17:13 |
|
Thanks for the replies, I've got it working
|
# ? Aug 23, 2007 17:28 |
|
I'm either going to get started learning PHP or Ruby on rails. I'm currently leaning towards php. Will this be a mistake in the future?
|
# ? Aug 23, 2007 22:18 |
|
cYp posted:I'm either going to get started learning PHP or Ruby on rails. I'm currently leaning towards php. Will this be a mistake in the future?
|
# ? Aug 23, 2007 23:29 |
|
cYp posted:I'm either going to get started learning PHP or Ruby on rails. I'm currently leaning towards php. Will this be a mistake in the future? Well you can either learn RoR which encourages you (but doesn't guarantee you to) use good programming practices and will (after some experience behind your belt) get you working on cool projects with people that (on average, compared to php) know what they doing, and you'll be set to head into all sorts of new directions (the skills you learn apply everywhere, even PHP dev). Or you can learn PHP, write lovely code (which everyone always does when they start of, but...), never grow out of it, beg for poo poo work from rent-a-coder while competing against half of asia, grow insane with the cluster-gently caress of code you'll usually have to deal with and the people that wrote it, until you eventually decide you either need to take up accounting or learn a new programming skill. It's not PHP itself that is the problem (... for the most part...), it's the environment that grew around it. It is not always the case, but most PHP 'careers' tend towards nasty, brutish and short. It also doesn't have to be Rails you start with. Python, Perl, even Java (The Great Satan for most rails peeps) are all much more useful to learn. You could also jump into the really really really deep end and start by learning Haskell. It's not for the faint of heart but if you can gork Haskell, anything else you learn will be a walk in the park. ( it is also somewhat easier to learn haskell as your first language rather then your second or subsequent one).
|
# ? Aug 24, 2007 05:38 |
|
Mr. Wynand posted:It also doesn't have to be Rails you start with. ... Perl you will never fix all the damage
|
# ? Aug 24, 2007 05:45 |
|
Mr. Heavy posted:This was my first language and dear loving God do not do this still better then php
|
# ? Aug 24, 2007 05:48 |
|
Mr. Wynand posted:still better then php true dat
|
# ? Aug 24, 2007 06:31 |
|
atastypie posted:Hobo is brand new, so there is very little up to date documentation let alone an entire book. You could print off the docs from the website and reference those instead. Out of curiosity, why are you using habtm instead of has_many in this situation? This looks like an instance where an author should have many books and a book belong to an author. Your domain may be a bit different though. Anyway, you should just be able to do the following: author = Author.find(:first) price = author.books.sum(:price) However, you would want to do something like this: Models: code:
code:
Not sure what reasons you have for making price an integer, but it could be a decimal column as well. See http://pragdave.pragprog.com/pragdave/2006/07/decimal_support.html.
|
# ? Aug 24, 2007 07:57 |
|
Many books have multiple authors. There are so many real world examples on this that I don't even know where to start with an example. I'm just a newbie, but habtm on first glance would make sense to me on that.
|
# ? Aug 24, 2007 09:25 |
|
crazysim posted:Many books have multiple authors. There are so many real world examples on this that I don't even know where to start with an example. I'm just a newbie, but habtm on first glance would make sense to me on that. There's also has_many :through, which can let you flesh out the relationship a more than a habtm can.
|
# ? Aug 24, 2007 13:37 |
|
cYp posted:I'm either going to get started learning PHP or Ruby on rails. I'm currently leaning towards php. Will this be a mistake in the future?
|
# ? Aug 24, 2007 13:39 |
|
So I'm thinking of starting a project with RoR but have one question: Is there a suitable way to do user registration, authentication, etc? Granted, I haven't looked into it very much, but all authentication stuff seems to be either the entire site or nothing. What I'd specifically like to do is to protect an admin control panel along with admin-only elements/controls on an otherwise publicly viewable page. Is this built into RoR and I just missed it? Are there any gems available to do this? How hard is this to implement?
|
# ? Aug 28, 2007 20:41 |
|
scr0llwheel posted:So I'm thinking of starting a project with RoR but have one question: Is there a suitable way to do user registration, authentication, etc? Granted, I haven't looked into it very much, but all authentication stuff seems to be either the entire site or nothing. What I'd specifically like to do is to protect an admin control panel along with admin-only elements/controls on an otherwise publicly viewable page. There's a plugin called restful_authentication that's pretty much the standard if you're not going to write something custom. It'll give you all the username/password/login/session stuff, and you can build from that.
|
# ? Aug 28, 2007 21:07 |
In C# I have the '??' operator, which when used like 'a ?? b', returns a unless it is a null object, in which case it returns b. Is there anything like that in Ruby? EDIT: Wow, ignore that. I was retarded. My original question still stands. HIERARCHY OF WEEDZ fucked around with this message at 00:27 on Aug 29, 2007 |
|
# ? Aug 28, 2007 23:55 |
|
shopvac4christ posted:In C# I have the '??' operator, which when used like 'a ?? b', returns a unless it is a null object, in which case it returns b. Is there anything like that in Ruby?
|
# ? Aug 29, 2007 00:36 |
|
scr0llwheel posted:So I'm thinking of starting a project with RoR but have one question: Is there a suitable way to do user registration, authentication, etc? Granted, I haven't looked into it very much, but all authentication stuff seems to be either the entire site or nothing. What I'd specifically like to do is to protect an admin control panel along with admin-only elements/controls on an otherwise publicly viewable page. If all you need is one admin user then you don't need restful_authentication, this is much simpler and should fulfill your need: Controller: code:
code:
Nolgthorn fucked around with this message at 03:13 on Aug 29, 2007 |
# ? Aug 29, 2007 03:10 |
|
Rails makes me cry when I look at the SQL calls. I mean, it's very easy to get a working application, but then you wonder why it's slow, and it's because it's doing 100 db calls for a 100 item list. Oy. Given that, I did write a whole website in it, and it has actual users who aren't me. And I haven't touched it in 6 months and it's still working, so not bad.
|
# ? Aug 29, 2007 03:26 |
|
smackfu posted:Rails makes me cry when I look at the SQL calls. I mean, it's very easy to get a working application, but then you wonder why it's slow, and it's because it's doing 100 db calls for a 100 item list. Oy. You're right it's not perfect but you also have to use it properly. @authors = Authors.find(:all, :include => ["books", {"screenplays" => "movie"}]) If the application is making 100 db calls for a 100 item list then you have forgotten to use eager loading. Now you can loop through, request the author.books or whatever and it won't have to get that information from the database for each one. Edit: Sorry, not intended to sound mean. Nolgthorn fucked around with this message at 07:15 on Aug 30, 2007 |
# ? Aug 29, 2007 03:36 |
freeb0rn posted:The or operator (||) in Ruby can work like this. Should have thought of that. Also, holy crap Hobo is a huge framework. The stack traces are twice as long and I haven't even started *coding* yet. I think this may be too much magic for what I'm trying to do.
|
|
# ? Aug 29, 2007 15:19 |
|
I've been trying to learn Ruby on Rails on and off for a while, and I'm back on an ON kick again. I'm working on something that I'd want to have a forums auth for; I've written one in PHP before and it requires setting a cookie and setting your own HTML headers and everything (you can't view profiles without being logged in). How would I even begin to try this in RoR? Also a lot of the AJAX stuff is nice but good lord is it black magic. I follow little tutorials on how to do stuff and it just says "put this here" and I do but I have no idea WHY. I've written AJAX applications by hand before, writing my own xmlhttprequests and response scripts, so I get the mechanics of it but I am having a hard time figuring out how to get to the point in RoR where I can say, "ok I want an AJAX thing to do this, so I'd have to write code with this structure and syntax:".
|
# ? Aug 29, 2007 23:21 |
|
Space Kimchi posted:Also a lot of the AJAX stuff is nice but good lord is it black magic. Start with using the rjs templates and what not. Then start to actually learn Javascript and Prototype. I'm on the second step currently, and while I might not be the best javascript guy, I know what's going on and it doesn't feel like black magic anymore. And if you ever are wondering why something works the way it does in rails, start reading the rails source code. It's not that scary, I promise.
|
# ? Aug 30, 2007 02:32 |
|
Anal Wink posted:Start with using the rjs templates and what not. Then start to actually learn Javascript and Prototype. I'm on the second step currently, and while I might not be the best javascript guy, I know what's going on and it doesn't feel like black magic anymore. It's more like, I don't get the logic at all behind the requests and responses. Indeed, I probably need to "get" Prototype more. I'll just have to play with it a bit, I think last time I was messing with it I started examining the xmlhttprequests and everything and figured out what it was doing and it started to make SOME sense.
|
# ? Aug 30, 2007 02:43 |
|
Speaking of AJAX, is there some kind of way to retrieve an instance of a model as a javascript object? I mean, if you have a model called Book, and it has the fields title, description, ISBN, is there a function that will let me go myBook = theFunction(myBookId), such that I can say myBook.title, etc?
|
# ? Aug 30, 2007 03:34 |
|
Space Kimchi posted:It's more like, I don't get the logic at all behind the requests and responses. Indeed, I probably need to "get" Prototype more. I'll just have to play with it a bit, I think last time I was messing with it I started examining the xmlhttprequests and everything and figured out what it was doing and it started to make SOME sense. If you aren't using Firebug, start. That's step one, step two, and step three. Argue posted:Speaking of AJAX, is there some kind of way to retrieve an instance of a model as a javascript object? I mean, if you have a model called Book, and it has the fields title, description, ISBN, is there a function that will let me go myBook = theFunction(myBookId), such that I can say myBook.title, etc? Jester does this. Looks cool, but I haven't tried it personally.
|
# ? Aug 30, 2007 04:34 |
|
savetheclocktower posted:If you aren't using Firebug, start. That's step one, step two, and step three. You mean there's another way to do that? ;D And god dammit, I never thought that my problem writing an SA auth would be more with "how do i functioned ruby" than "how do i grabbed something with cookies" For the curious, here's what I have so far. The page nabbing works great, but I wanted to test my newly-added logic and whatnot. Note that the cookie is copied and pasted directly from the Cookie: line in the HTTP headers when I normally visit a page, on SA all of them. When I wrote a PHP one, I discovered that being selective doesn't work too well. Of course since you could use that to log in as me, I have removed it code:
Now I'd love to test it on my ruby script/console deal, but I can't figure out how to invoke it Should this kind of thing be in Helpers? Oh god MVC Edit: fixed some syntax after I had a chance to test it, I have to include the helper in script/console Now I just have to figure out why it returns true no matter what now when it worked before! Space Kimchi fucked around with this message at 10:14 on Aug 30, 2007 |
# ? Aug 30, 2007 08:19 |
|
This is just wild guessing and from playing with ruby.code:
|
# ? Aug 30, 2007 10:38 |
|
crazysim posted:This is just wild guessing and from playing with ruby. Yeah I got rid of mode, it was a dumb idea. code:
Edit: Also I must say, I'm impressed. I remember the equivalent PHP code being bigger, clunkier, and a bigger pain in the rear end to figure out; I had to send a WHOLE raw HTTP request, if I recall, or at least I remember it took a while to figure out it wasn't working because of the lack of the proper number of newlines after the Cookie: line, heh. Edit2: And I confess I mostly lifted the net code from some tutorial or snippet I found and figured out how to add cookies and adjusted it to my nefarious means. In other words, don't ask me what response.value is or what it does, as I don't know. Or even EXACTLY why it's in a do|| loop, as I can only vaguely guess. Space Kimchi fucked around with this message at 11:04 on Aug 30, 2007 |
# ? Aug 30, 2007 10:57 |
|
Space Kimchi posted:Oh god MVC I don't think making it a helper is the right thing to do. This either wants to be its own class which would live in app/models (if you wanted to be all restful about it) or a class in lib.
|
# ? Aug 30, 2007 11:30 |
|
Is anyone doing RailsRumble (railsrumble.com)? A team of four of us at my work are.
|
# ? Aug 30, 2007 15:42 |
|
I've been using Ruby for a while now, but this is my first foray into Rails (I'm a big fan of Camping, but past a certain size Camping apps get difficult to handle). I want to be able to do this in a controller method: code:
code:
|
# ? Aug 30, 2007 18:17 |
|
Al Azif posted:I've been using Ruby for a while now, but this is my first foray into Rails (I'm a big fan of Camping, but past a certain size Camping apps get difficult to handle). before_filter :get_session_user Then in application.rb make a private method that does @user = find_user.
|
# ? Aug 30, 2007 18:33 |
|
Space Kimchi posted:
Just to make it clear, I'm really hoping for more response to this, as I'm used to being Fort Knox with PHP and I'm not sure what I have to do or how careful I have to be in Rails. And thanks Wink, making it a Model class sounds like a good idea. RESTzis can pretty much suck it imo, I'm keeping my verbs god dammit. I never liked the stateless nature of HTTP anyway. If you do, that's great, I just don't care and am going to use all the goddamned verbs and session cookies I please.
|
# ? Aug 30, 2007 19:54 |
What's a good way to figure out which submit button on a form was clicked if all of them have the same name?
|
|
# ? Sep 1, 2007 05:33 |
|
shopvac4christ posted:What's a good way to figure out which submit button on a form was clicked if all of them have the same name? Not entirely sure if this is the solution you need, but the with action plugin lets you easily use multiple buttons within a form. You would be able to give each button it's own name.
|
# ? Sep 1, 2007 06:14 |
|
Argue posted:Speaking of AJAX, is there some kind of way to retrieve an instance of a model as a javascript object? I mean, if you have a model called Book, and it has the fields title, description, ISBN, is there a function that will let me go myBook = theFunction(myBookId), such that I can say myBook.title, etc? Jester is prolly overkill - just use @book.to_json
|
# ? Sep 2, 2007 21:33 |
|
I just broke something when I updated rails from the gem [to edge rails] and I can't figure on how to fix it.... here's what my error log shows:code:
|
# ? Sep 3, 2007 16:42 |
|
|
# ? Apr 27, 2024 04:24 |
|
MrSaturn posted:It looks like I have to set some keyword for my cookie? Where and how do I do that? In other words, stick that line in the config section of your environment file. And change the key and secret values.
|
# ? Sep 3, 2007 17:20 |