|
Hey everyone, I recently just installed Ruby, Rails, and MySQL to my home machine and I'm trying to get into development. I'm using this: http://www.tutorialspoint.com/ruby-on-rails-2.1/index.htm tutorial and I've gotten up to making the "book" controller but whenever I go to localhost:3000/book/list or localhost:3000/book i get a routing error saying there's no route to that page. I don't know what I'm doing wrong.
|
# ? Nov 23, 2008 17:15 |
|
|
# ? May 28, 2024 01:05 |
|
Your controller should be called books_controller.
|
# ? Nov 23, 2008 20:05 |
|
walnutz posted:I don't know what I'm doing wrong. Also, that tutorial doesn't seem to follow any of the newer Rails 2.1 conventions. It looks like it was written for 1.0. I would be weary of picking up bad habits from it. Unfortunately, I cannot suggest a better one for you to follow.
|
# ? Nov 23, 2008 20:19 |
|
skidooer posted:Do you have at least the default route in your routes.rb file? All I had to do was apparently just restart the server. I don't know why. Is there a book that covers the latest version of Ruby/Rails? I don't mind picking a book up.
|
# ? Nov 24, 2008 04:58 |
|
You have to restart your server any time you change your routes file. I don't know if there are any Rails 2.0+ friendly books that have been published recently. I really enjoyed many of the PeepCode screencasts. You're probably most interested in Rails 2 From Scratch (Part 1, Part 2). Their rSpec, Passenger, and Capistrano videos are all great too.
|
# ? Nov 24, 2008 05:28 |
|
atastypie posted:You have to restart your server any time you change your routes file. That is false, you do have to restart your server anytime you change your environment.rb, database.yml, or vendor directory. Routes can be altered on the f.l.y.
|
# ? Nov 24, 2008 10:11 |
|
Nolgthorn posted:That is false
|
# ? Nov 24, 2008 16:21 |
|
Weird, I swear that when I started out with 1.6 that you had to restart your server to get the routes file to reload. That, plus comments like '# Be sure to restart your web server when you modify this file.' in environment.rb made me just assume anything in /config required a restart. I've also done a lot of work with Radiant, and any routes found in an extension require a restart in order to be found. Combine those two and I guess I learned a bad (useless?) habit.
|
# ? Nov 24, 2008 17:42 |
|
atastypie posted:Weird, I swear that when I started out with 1.6 that you had to restart your server to get the routes file to reload. That, plus comments like '# Be sure to restart your web server when you modify this file.' in environment.rb made me just assume anything in /config required a restart. I've also done a lot of work with Radiant, and any routes found in an extension require a restart in order to be found. Combine those two and I guess I learned a bad (useless?) habit. I believe the restarting for routes requirement was only removed in 2.0+, though I could be wrong on this. You also have to restart if you make any modification to files in lib. I've got a bad habit, I restart my development mongrel waaaay too much.
|
# ? Nov 24, 2008 23:47 |
|
Hammertime posted:You also have to restart if you make any modification to files in lib.
|
# ? Nov 25, 2008 00:07 |
|
skidooer posted:No you don't, unless you explicitly require the file that is. But apparently 2.2 really does have a problem with routing to new controllers without a restart. I just encountered it. Well, yes, but what's the point in having lib files if you don't require any of them?
|
# ? Nov 25, 2008 07:52 |
|
Hammertime posted:Well, yes, but what's the point in having lib files if you don't require any of them?
|
# ? Nov 25, 2008 17:10 |
|
How do you guys do "admin sections" of an application? All of the solutions I have come up with / have seen leave a lot to be desired; either by way of duplication of efforts, ugly code, or what have you. There much be a better way.
|
# ? Dec 3, 2008 16:06 |
|
skidooer posted:How do you guys do "admin sections" of an application? All of the solutions I have come up with / have seen leave a lot to be desired; either by way of duplication of efforts, ugly code, or what have you. There much be a better way. I usually use a base controller that all of my admin controllers inherit from, in addition to an 'admin' namespace. The base controller will use a before_filter that will require a logged in user with admin? privileges. That will take care of most of the duplication right off the bat. In addition, I normally use a pretty slim layout just to make things efficient. Also, you can use an Admin:: namespaced helper just for your admin-related shennanigans. There are some times where you can work the admin interface into the site itself. I've found that to be a poor solution, especially for any more than the simplest of admin interfaces.
|
# ? Dec 3, 2008 23:51 |
|
I've been using Rails for a while, but I want to know the "correct" way to do this (using RESTful routes?): I have three models, Menu, MenuItem, and MenuMember. Menu(:id, ...) MenuMember(:id, :menu_id, :menu_item_id, :is_default, ...) MenuItem(:id, ...) Menu has_many :menu_members Menu has_and_belongs_to_many :menu_items, :through => :menu_member I want to have an edit view in MenuConroller where you can add MenuItems to it. It needs to be more complex than just a multiselect - I want to to be able to edit the MenuMember objects along with the Menu on the same page. Is the way to do this by setting up: map.resources :menu, :has_many => :menu_members So I can call /menu/1/menu_members/new/, etc. and then in the MenuMember controller have each action check for params[:menu_id]? That seems a little clunky. Is there a best way to do what I'm looking for?
|
# ? Dec 4, 2008 05:06 |
|
Hop Pocket posted:That will take care of most of the duplication right off the bat. mynameisntneo posted:Is there a best way to do what I'm looking for? code:
skidooer fucked around with this message at 05:22 on Dec 4, 2008 |
# ? Dec 4, 2008 05:19 |
|
skidooer posted:The duplication I was referring to was how the admin and main site controllers end up being almost exactly the same, only different. Different enough that using one controller to serve both views doesn't work well either. Writing the application twice, so to speak, gets old. Maintaining the site twice is even worse. Well, ok. How about using something like resource_controller to cut down on the controller cruft, assuming you're OK with REST, and then incorporate the scaffolding views into your admin area so that you don't have to keep up with each maintained field. If you query the model for its attributes and then iterate over them, creating form fields for those attributes, then that takes a lot of the drudgery out of it and your forms grow as your models do.
|
# ? Dec 4, 2008 23:22 |
|
Question about adding Restful Authentication to a Rails 2.2 app: I followed the tutorial here http://www.avnetlabs.com/rails/restful-authentication-with-rails-2 But the guy doesn't say how to actually protect the controllers you want to require login for. Anyone know how?
|
# ? Dec 6, 2008 23:31 |
|
phazer posted:Question about adding Restful Authentication to a Rails 2.2 app: I'd guess a :before_filter in your application controller, but I'm not at work so that name might be wrong.
|
# ? Dec 6, 2008 23:46 |
|
Trabisnikof posted:I'd guess a :before_filter in your application controller, but I'm not at work so that name might be wrong.
|
# ? Dec 7, 2008 00:27 |
|
sorghum posted:Yeah, it's before_filter :login_required in whatever controllers you want to protect. You can also use the :except and :only options to limit it to certain actions - for example before_filter :login_required, :except => [:index, :show]. When I use before_filter :login_required I get an undefined method error. code:
edit: OK I don't know what's going on, but I am doing this on Media Temple hosting, and I thought well maybe I should restart the application, maybe that will get some of my changes to take effect. So I went to restart it and the mongrel.pid file got deleted and now my drat application won't start. Media Temple support was no help last time I had this problem. (we don't support custom code, etc. well what's the point then?) Can anyone help? phazer fucked around with this message at 01:19 on Dec 7, 2008 |
# ? Dec 7, 2008 00:52 |
|
I've actually only used an old version of Restful Authentication, so I'm not sure what's happening there. Could you post the stack trace? Check the log files if you can't start the application. It shouldn't have anything to do with the mongrel.pid file though - that file is only supposed to exist while the application is running.
|
# ? Dec 7, 2008 03:13 |
|
phazer posted:When I use before_filter :login_required I get an undefined method error. 1) I have a feeling that in your action you are trying to muck with a "login" variable that is undefined- if there is no local variable defined, it will look for it in the next best place- a method on your BandsController instance (where it can't find it because it doesn't exist, so it tosses). The important thing to remember here is that Rails controllers aren't magic. Your "actions" are just methods in a class. Each action is an instance method, and "self" inside of actions is the instance of your controller class. (If that doesn't make sense, Google "Object-Oriented Programming") Try to think of what you're doing inside of a Rails action as a normal method call, in a normal class only your return is a little weird (You are quite literally returning your render/redirect method call). 2) The media temple stuff has nothing to do with this. You should be doing all of this stuff locally anyways. Only once you get a working application should you be deploying to a webhost. For some reason I'm assuming you're on windows- don't they have one-click Rails installs and whatnot? Use those.
|
# ? Dec 9, 2008 22:37 |
|
edit: nevermind
dustgun fucked around with this message at 15:24 on Dec 10, 2008 |
# ? Dec 10, 2008 06:36 |
|
Praetorian42 posted:1) I have a feeling that in your action you are trying to muck with a "login" variable that is undefined- if there is no local variable defined, it will look for it in the next best place- a method on your BandsController instance (where it can't find it because it doesn't exist, so it tosses). I did have a working application before I deployed. In fact, it was working AFTER deployment until this restart issue. It is Media Temple. They said my Mongrel gem is corrupt and they don't know why. And I'm on OS X.
|
# ? Dec 10, 2008 18:43 |
|
phazer posted:I did have a working application before I deployed. In fact, it was working AFTER deployment until this restart issue. It is Media Temple. They said my Mongrel gem is corrupt and they don't know why. And I'm on OS X. Well, to be sure, the mongrel pid problem and the nomethoderror problem are two different problems. If it is working locally but not working remotely on the same code, all I can say is make sure you've run your migrations. The chances of your mongrel gem being corrupt are slim to none. The mediatemple people have no idea what they're talking about. How did you do the restart? Is this a full-on VPS or are you stuck on some shared thing?
|
# ? Dec 10, 2008 22:42 |
|
phazer posted:I did have a working application before I deployed. In fact, it was working AFTER deployment until this restart issue. skidooer fucked around with this message at 22:56 on Dec 10, 2008 |
# ? Dec 10, 2008 22:52 |
|
skidooer posted:Have you diffed the source on the server with the deployed revision? Perhaps a colon accidentally disappeared from a symbol, for example. Then, when you restarted your application the new code was loaded into memory and boom, your code was then broken. Well, since on MT, the app runs in Production mode, I figured my problem was I needed to restart the app after making changes to controllers and what-not. I went to restart my app, and the mongrel.pid issue happened. Regardless, it's all useless until they fix it. They escalated me to higher-tier support. Thanks for all the help so far, though!
|
# ? Dec 11, 2008 20:56 |
|
phazer posted:I went to restart my app, and the mongrel.pid issue happened. code:
|
# ? Dec 11, 2008 21:05 |
|
skidooer posted:Run this: I got: code:
|
# ? Dec 11, 2008 22:07 |
|
And what did you get when you started your application?
|
# ? Dec 11, 2008 23:37 |
|
phazer posted:I got: Just do code:
|
# ? Dec 12, 2008 00:48 |
|
skidooer posted:And what did you get when you started your application? code:
When I grep for a mongrel process, I get no results.
|
# ? Dec 12, 2008 11:39 |
|
Can someone point me in the right direction for doing multiple file uploads in Rails2? I want to have 1 upload field with the ability to add more through AJAX. I'm googling but finding nothing valuable.
|
# ? Dec 12, 2008 14:31 |
|
phazer posted:When I grep for a mongrel process, I get no results. code:
|
# ? Dec 12, 2008 15:30 |
|
skidooer posted:Try: Same exact error. Like I said, MT support is on it... just waiting to hear back.
|
# ? Dec 12, 2008 15:51 |
|
phazer posted:Same exact error. Like I said, MT support is on it... just waiting to hear back. Ugh. I'd ditch MT if I were you. I had a deal for free MT hosting for a year and after 6 months decided to pay for hosting rather than keep using them. They're really quite awful. Get a $20 account at Slicehost. Sure it might be a bit more, but you'll be saving yourself so much time by not having to deal with the crap that MT forces you through.
|
# ? Dec 12, 2008 17:59 |
|
Do you mean MT in general, or MT specifically for Rails?
|
# ? Dec 12, 2008 18:23 |
|
atastypie posted:Do you mean MT in general, or MT specifically for Rails? MT for Rails. If you use PHP, I'd imagine it would be just fine.
|
# ? Dec 12, 2008 20:03 |
|
|
# ? May 28, 2024 01:05 |
|
Praetorian42 posted:Ugh. I'd ditch MT if I were you. I had a deal for free MT hosting for a year and after 6 months decided to pay for hosting rather than keep using them. They're really quite awful. I will say deploying an existing rails app on Media Temple was WAY easier than dreamhost. (before i decided to restart the application)
|
# ? Dec 12, 2008 21:52 |