|
zigb posted:Documentation. For gently caress's sake people, at least pretend like you're trying. quote:Server restarts. Our dev server is also, unfortunately, a production server for different apps in other languages. (don't blame me, I didn't do it ). quote:Added/Edited something in the /lib path? Restart Apache. This makes any sort of iterative development of libs/mixins a huge pain in the rear end. quote:SQL Logging. Didn't work, even when I triple checked that the /tmp and /log dirs had proper permissions and that logging wasn't disabled in the environment files. quote:Not that I mind writing SQL, but I prefer to write it in one large understandable chunk instead of splitting it up into mini-clauses, like :conditions => "[some sql]", :order => "[some sql]", etc. Although it's rare that I find myself writing any SQL at all. I'll assume it's your use of a schema that wasn't designed for ActiveRecord that you had to write a lot of SQL to work around those limitations. quote:Most find queries that required a JOIN or two had to be written using find_by_sql. quote:Controller initialize function. It causes "Internal Server Error" when I put simple logic in there. Example (this kills rails): "if null != params[:a_param]; end". Same thing when I put the logic in question into a method and call it from initialize. No problems when I call that same method from one of the actions instead. quote:Different expectations for overriding ActionController::initialize and ActiveRecord::initialize. quote:While the above issues were all annoyances, the need to restart Apache after making code, not configuration, changes is the kicker. skidooer fucked around with this message at 17:50 on Nov 20, 2007 |
# ? Nov 20, 2007 17:43 |
|
|
# ? Apr 26, 2024 20:22 |
|
Having had to unfortunately work with FastCGI instead of Mongrel recently, I can understand your pain. But yeah, try to look into using Mongrel instead.
|
# ? Nov 20, 2007 17:49 |
|
skidooer posted:Why bother with someone's english interpretation when you've got perfectly good source code to go by?
|
# ? Nov 20, 2007 17:58 |
|
I have been solving an unusual problem with rails, so far with very little trouble at work. Part of the product we ship people is a web interface that runs off a single executable and does not deploy to IIS or apache. The other kicker is that it has to dynamically support sqlite, sql server, oracle and soon mysql by reading the registry. I am still in the early stages of development but have been amazed at how easy it has been to accomplish this stuff. My question is thus, in the other parts of our product we make "smart" update statements. So if you edit a user you pass the changed user and the original user and then you get an update statement that only updates changed fields. Is there a mechanism for this in activerecord? Do I have to make my own?
|
# ? Nov 20, 2007 19:08 |
|
skidooer posted:I suppose it might be a little daunting for the first time user. Honestly, I prefer to just read the source code anyway. Why bother with someone's english interpretation when you've got perfectly good source code to go by? Why read source code when you have a perfectly good English explanation to go by? Of course in Rails you almost never do, but that's just a weakness of Rails more than anything else.
|
# ? Nov 20, 2007 19:38 |
|
wunderbread384 posted:Why read source code when you have a perfectly good English explanation to go by? skidooer fucked around with this message at 20:08 on Nov 20, 2007 |
# ? Nov 20, 2007 20:01 |
|
code:
|
# ? Nov 20, 2007 20:35 |
|
For those of you using Mongrel in a deployment environment, how many Mongrel processes do you start? I know that it's all dependent on the application, load, # of static pages, etc. I'm setting up some hosting with Joyent, and you have to request Mongrel ports for a shared hosting environment, so I was just curious.
|
# ? Nov 20, 2007 20:37 |
|
spacepirate posted:Fantastic, self explaining code right there, especially since create_or_update is not listed in the Rails API. Yeah, that isn't exactly ideal, but it's not like this should be a problem. Your first reaction when you see something like that is: 1) search/grep for 'def create_or_update' if you're reading the source in a text editor or 2) google 'rails create_or_update' Both of those will net you the answer within 10 seconds, and the code is simple enough that you should know what's going on as soon as you finish reading it. No need for extra documentation there :S code:
hmm yes fucked around with this message at 20:58 on Nov 20, 2007 |
# ? Nov 20, 2007 20:55 |
|
spacepirate posted:Fantastic, self explaining code right there, especially since create_or_update is not listed in the Rails API.
|
# ? Nov 20, 2007 21:03 |
|
Hop Pocket posted:For those of you using Mongrel in a deployment environment, how many Mongrel processes do you start? I know that it's all dependent on the application, load, # of static pages, etc. I'm setting up some hosting with Joyent, and you have to request Mongrel ports for a shared hosting environment, so I was just curious. My site, Forumwarz runs on 10 Mongrels behind an nginx proxy. It's pretty snappy, each Mongrel process seems to be using about 50-60M of RAM on a 2.4Ghz Core2Duo dedicated server.
|
# ? Nov 20, 2007 21:46 |
|
First off, I want to say that I really appreciate people taking the time to try to address some of the issues I had mentioned with our rails setup. When I hit the post button late last night I was expecting to be flamed out of hand. Maybe I'll have to spend more time in the COBOL cavern and try to help out where possible. I'll address skidooer's responses because he was very thorough and his responses captured the gist what everybody seems to be saying: skidooer posted:Is there any reason why you aren't developing on your local system? That is the Rails way. I would have preferred that. I work on a machine that is managed by our IT staff, who are extremely paranoid and won't install anything resembling a server, even if I can lock it down to local access only. To put things in perspective, I had to get permission from my supervisor and dept. head before they would install WinMerge. Basically, local dev is out. anal wink posted:Is there a reason you're not using mongrel? wunderbread384 posted:...why are you running FastCGI for your development server? It's not my server, I have no choice. In fact, I barely have a user account. I'm grateful for the comments people left re: FastCGI because if I can eliminate the Apache restarts (well, make the case to the server admin and hopefully get a change) I'd be a much happier camper. In order to help resolve my ignorance on the matter, can I run Mongrel behind Apache? The decision has been made that Apache WILL be our http server, so any solutions I come up with need to be Apache-centric. skidooer posted:Unless you were using an ancient version of Rails, or running in production mode, that isn't true. Rails 1.2.3 on Ruby 1.8.5. We're currently supporting another RoR app written by a different dev on this same box, so neither of those are subject to change. Also, I'm running in development mode. skidooer posted:[re: SQL Logging]I've never seen it not work in development mode. I hate always being the exception to the rule! skidooer posted:I'll assume it's your use of a schema that wasn't designed for ActiveRecord that you had to write a lot of SQL to work around those limitations. skidooer posted:find(:all, :joins => 'INNER JOIN bar ON bar.foo_id = foo.id') Likely too true. I'll have to try that :joins thing, btw, I was totally unaware it existed .. grob posted:-- what kind of joins are you doing that aren't handled elegantly by ActiveRecord? Don't say you didn't ask for it ... This is for a reports type section of the site. The nastiness of this has much to do with the enforced crappy DB schema. Here's as brief an explanation as I can muster.. Payments belong to Schools and Costs. Costs belong to DatabaseInformations, which are really what this app is tracking. I need a list of all payments within a date range, for a few specific Schools. The date range is determined by Cost.subscriptionStart and Cost.subscriptionEnd. I need to order these Payments for display by the Payment.school.schoolName, then Payment.school.library, then Payment.cost.databaseInformation.databaseName. Final note: this report gets run perhaps twice in a blue moon, so the inefficient SQL doesn't make me too nervous. @skidooer - I guess I just proved your point about reading English where the code might be more straightforward. I can only plead my desire to very briefly explain the query below without getting too far into specifics. code:
skidooer posted:params is your problem here. It's nil. There is no [] method defined for NilClass. If you're doing what I think you are, you want to use a before_filter instead. skidooer posted:The odds that you'd ever want to overwrite initialize in either class are extremely low. I can't think of any reason why you'd ever want to, really. Taking your second statement first, is a controller's initialize method not the best place to put code that I want executed for each action? It seems DRYer than making a separate method and calling that from each action. I also think we've got a slight terminology mismatch here. Anytime I define a function that's already been defined in a base class I'm overriding it, whether I call super() from it or not. Of course if I call super() at the start of my newly declared method I'm really just modifying the existing functionality instead of providing entirely new functionality. You're saying that params is unavailable/nil in a controller's initialize method? Any specific reason why? If not this is still good to know. My code that it barfed on was something like "if nil != params[:date_from] && nil != params[:date_to]". I was basically setting up some default vars for the actions if those parameters had been provided. Again, thanks everybody for the constructive comments, I'll be looking forward to lending a hand where I'm qualified to in this forum. zigb fucked around with this message at 22:47 on Nov 20, 2007 |
# ? Nov 20, 2007 22:41 |
|
zigb posted:Taking your second statement first, is a controller's initialize method not the best place to put code that I want executed for each action? It seems DRYer than making a separate method and calling that from each action. Sucks about your development environment, that's ridiculous. Anyway, what you're looking for here is before_filter. http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html In Rails tradition the docs are lovely, but essentially you can do: code:
code:
|
# ? Nov 20, 2007 23:15 |
|
code:
This won't work properly otherwise without a little bit of extra declarations in your model and such specifying the ruby-way ness. You may have to fix the pluralization, to make tables the ruby way have them all named in the pluralized sense. Then to get information from it, pluralization starts to depends on what kind of relationship the tables have with one another. This should approximately begin to start to get at what you are going for. I think it might be a needlessly complex task, I don't know what the function of your application is so I can't tell. code:
Good luck!
|
# ? Nov 20, 2007 23:19 |
|
zigb posted:Rails 1.2.3 on Ruby 1.8.5. We're currently supporting another RoR app written by a different dev on this same box, so neither of those are subject to change. Also, I'm running in development mode. zigb posted:If there's some way AR would make this statement go away, I want to know about it! code:
At very least take the SQL out of your controllers. The only place that belongs is in the model. zigb posted:Taking your second statement first, is a controller's initialize method not the best place to put code that I want executed for each action? code:
zigb posted:You're saying that params is unavailable/nil in a controller's initialize method? Any specific reason why? skidooer fucked around with this message at 23:35 on Nov 20, 2007 |
# ? Nov 20, 2007 23:32 |
|
I have a question about using forms. For this project I am doing, I have Events and Categories. An Event belongs_to a Category, so I have the event.category relationship. In my Event form, I want to represent this as a select list. However, I am not really sure of the best way to go about it. I'm currently trying: code:
code:
In Spring WebMVC, we used PropertyEditors to handle the conversion to and from ids and model objects. Is there anything like that in Rails? What's the 'normal' way to go about linking up a separate model object in a form?
|
# ? Nov 21, 2007 18:46 |
|
Shouldn't you just assign the id to the category_id property of Event? Or, you could do my_event.category = Category.find_by_id(the_id); I don't know which is the recommended way.
|
# ? Nov 21, 2007 19:00 |
|
You can assign the category_id field instead:code:
code:
skidooer fucked around with this message at 19:20 on Nov 21, 2007 |
# ? Nov 21, 2007 19:05 |
|
Thanks guys. Assigning it to the category_id seems to work well.
|
# ? Nov 21, 2007 19:32 |
|
You've all been really helpful. I have one more question. I'm writing my own form builder, and I want all of my form fields to go inside of a <table>. What I'd like to do is to:code:
code:
vvvv thanks, that worked perfectly Hop Pocket fucked around with this message at 16:10 on Nov 22, 2007 |
# ? Nov 21, 2007 21:29 |
|
Hop Pocket posted:I have one more question. I'm writing my own form builder, and I want all of my form fields to go inside of a <table>. code:
|
# ? Nov 22, 2007 07:32 |
|
One thing to consider is if you use Haml for markup (which I do and love), they have their own puts methods you can use in helpers, so your above code would work!
|
# ? Nov 22, 2007 16:16 |
|
Grob posted:One thing to consider is if you use Haml for markup (which I do and love), they have their own puts methods you can use in helpers, so your above code would work! I'm looking at the Haml documentation right now.. Looks awesome. Though, my production host (DreamHost) does not have the Haml gem installed. I Haml'd my rails app and it looks like it installs a plugin that simply requires the gem. Is there a way that I could install Haml on my project in a way that didn't require the gem to be installed on the production host? Also, thanks! edit: I think I figured it out: guiness:events$ ruby script/plugin install http://svn.hamptoncatlin.com/haml/tags/stable --force Hop Pocket fucked around with this message at 17:53 on Nov 22, 2007 |
# ? Nov 22, 2007 17:43 |
|
So I was pleasantly surprised to find rails 1.2.3 and sqlite3 installed as default when I upgraded to Leopard yesterday. Thanks, Apple (Thapple).
|
# ? Nov 22, 2007 18:49 |
|
A question on rollbacks using capistrano. I have about 15 migrations in my source code, and I decided to change migration #7 to change the column names of a model object. On my development machine, I simply rake'd it back and then forward again: $ rake db:migration VERSION=6 $ rake db:migrate I then committed my code. How then to do the same through capistrano for the production host? $ cap deploy:migrations VERSION=6 Did not work. It simply ran the migrations as if I had run $ cap deploy:migrations Ideas?
|
# ? Nov 23, 2007 17:57 |
|
I'm not really surprised since it came from _why, but Hpricot is simply gorgeous. I refactored the parsing code of an old app using htmltokenizer and BeautifulSoup into about 10% of the size and run time. Being able to use CSS and XPath selectors for this sort of stuff is incredible.
|
# ? Nov 23, 2007 23:27 |
|
Hop Pocket posted:A question on rollbacks using capistrano. I have about 15 migrations in my source code, and I decided to change migration #7 to change the column names of a model object. On my development machine, I simply rake'd it back and then forward again: The rule we follow on my team is that once a migration has been committed to SVN you should rarely go back and modify it to do things like change the column names. Between the time you committed and the time you decide to modify it, it could have been rolled out to testing, staging, and then production, not to mention other developer's machines. Unless there's a real good reason for doing otherwise, just add a new migration that alters the column names.
|
# ? Nov 23, 2007 23:31 |
|
ikari posted:The rule we follow on my team is that once a migration has been committed to SVN you should rarely go back and modify it to do things like change the column names. Between the time you committed and the time you decide to modify it, it could have been rolled out to testing, staging, and then production, not to mention other developer's machines. Unless there's a real good reason for doing otherwise, just add a new migration that alters the column names. Yeah, I can see where you're coming from. In my situation though the production server is really just the staging server -- i.e. that's where i show my work to my clients that are usually remote. So it would not have any far-reaching consequences for the most part. Does Capistrano not have this ability?
|
# ? Nov 23, 2007 23:37 |
|
Are there any good resources for Ruby + OpenGL or some 2D graphics library? I've got things worked out with glut but I don't fancy trying to load a texture... i've got a .c file which exports ruby functions to load a png, but no idea how to use it!
|
# ? Nov 24, 2007 06:18 |
|
I've got a controller set up like this:code:
|
# ? Nov 25, 2007 15:40 |
|
SeventySeven posted:I've got a controller set up like this: could you set a boolean value in method1 to true, so you know that when that value's true, it came from method 1? (then just reset it to false at the end of method 2)
|
# ? Nov 25, 2007 15:58 |
|
SeventySeven posted:I've got a controller set up like this: I'm sure there are ways of doing exactly what you want, but if possible you're better off not relying on a referrer. Some alternatives: - If you're just doing processing in method1, why not just render method2's template afterwards. Alternatively, break up the processing into a private non-rendering method and call it from method2. - Write to the user's session collection at the end of method1, check/erase it in method2. This method is still flawed though, as if the user doesn't reach method2 after the redirect they'll have a session token sitting around unused. - Though probably not what you're after, flashes can persist after a redirect.
|
# ? Nov 25, 2007 16:05 |
|
Thanks for the advice guys. Wouldn't you know it though, there was actually a really easy way of doing it. I was unaware you could just append arbitrary parameters to a redirect_to so all I did was made it redirect_to :action => "method2", :temp => true and checked params[:temp] in method2.
|
# ? Nov 25, 2007 16:42 |
|
I'm trying to write a barebones blog engine but am having trouble creating an admin section. I've googled quite a bit for the last few days and all I can find are plugins that do multiple user accounts/login/register crap. All I really want is a table with my username and password and an admin controller that requires me to login before I can access the forms to create and destroy entries and messages. I think the biggest problem I have is wrapping my head around REST and routes and MVC at the same time. I understand them individually but when mashed together, it gets confusing. I have a blog controller that is routed to '' so when i go to https://www.somesite.com I get the index.rhtml of the blog. I want to have https://www.somesite.com/admin require a login and then I want to be able to mess with entries and messages. Can I create an admin controller that can access the new/create/destroy REST modules of Entry and Message models?
|
# ? Nov 25, 2007 20:14 |
|
I've got another question: I'm trying to add an rss feed to my blog, but I'm missing something. In my blogposts controller, I added the following code (from http://paulsturgess.co.uk/articles/show/13-creating-an-rss-feed-in-ruby-on-rails):code:
What'm I doing wrong? I've restarted my servers, I've tried putting the def rss in the frontpage's controller and moving the accompanying rss.rxml file to that view folder, and nothing seems to fix this.
|
# ? Nov 26, 2007 03:02 |
|
MrSaturn posted:I've got another question: I'm trying to add an rss feed to my blog, but I'm missing something. In my blogposts controller, I added the following code (from http://paulsturgess.co.uk/articles/show/13-creating-an-rss-feed-in-ruby-on-rails): I'm not sure what could cause that problem, but here's my RSS implementation: rss_controller.rb code:
code:
|
# ? Nov 26, 2007 04:12 |
|
MrSaturn posted:I've got another question What do your routes look like for the blogposts controller? It looks like you have it set up for /blogposts/:id, which would explain why /blogposts/rss would screw up (it's looking for a post with id of "rss").
|
# ? Nov 26, 2007 06:32 |
|
ah I got it working now, I just set it up under a new controller. Is RSS a reserved controller name? if you want to see it, it's at http://puddl.es:3002/rssfeed This is pretty cool. I'm learning how to do about one new thing a week on rails, given the free time I have. I do rather enjoy all this. I think next I'm going to work on my display pages for each blogpost, then do some interesting ajax stuff. You guys are great help so far! Thanks!
|
# ? Nov 26, 2007 07:17 |
|
MrSaturn posted:ah I got it working now, I just set it up under a new controller code:
|
# ? Nov 26, 2007 16:03 |
|
|
# ? Apr 26, 2024 20:22 |
|
The discussion in the PHP thread about not putting any logic in the templates got me thinking. Would the template be better off separated from the view in Rails? I can imagine a RJS-like DSL for implementing the views. Something like the following: View: code:
code:
|
# ? Nov 28, 2007 08:41 |