Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Nigger Goku
Dec 11, 2004

あっちに行け
Yeah, I'm using Geokit and the atrociously-named 'ym4r_gm' plugin to generate maps and markers and it's been easy.

Adbot
ADBOT LOVES YOU

jonnii
Dec 29, 2002
god dances in the face of the jews
I'm building a restful API but I'm not entirely sure how to go about writing functional tests for it.

Currently I'm doing all my testing with curl, which is far from ideal. What I'd like to be able to do is something like:

def test_should_create_user
assert_difference 'User.count' do
post :create, :user => { :username => 'fred' }, :format => :xml
assert_xpath @response.body, "/user/username", "fred"
end
end

Is this possible? I don't seem to get any response body back when I post with the format being xml. There's probably some obscure blog somewhere that details this, but so far I haven't found anything...

edit:

I was just browsing through the beast forum repository and they do some xml related stuff here:

http://github.com/rubyonbr/beast/tree/master/test/functional/posts_controller_test.rb

Is this still the recommend approach?

jonnii fucked around with this message at 18:51 on Oct 22, 2008

skidooer
Aug 6, 2001

jonnii posted:

I don't seem to get any response body back when I post with the format being xml.
That's because you're not responding to the format :xml in your controller. Change the format to 'xml' (string, not symbol) in your test and it should work.

drjrock_obgyn
Oct 11, 2003

once i started putting pebbles in her vagina, there was no going back
Bump because Rails 2.2 rc1 is out:
http://weblog.rubyonrails.org/2008/10/24/rails-2-2-rc1-i18n-thread-safety-docs-etag-last-modified

Improvements include:
* Thread safety
* ActiveRecord connection pool
* Mailer layouts
* Ruby 1.9 compatibility
* Enhanced etag support
* Internationalization
* Full list of release notes

To install:
code:
gem install rails -s [url]http://gems.rubyonrails.org[/url] -v 2.2.0
This update will possibly break parts of your existing apps.

And a bit of shameless self promotion if you want a pdf/video of what's new:
http://envycasts.com/products/ruby-on-rails-22-package-deal

manero
Jan 30, 2006

drjrock_obgyn posted:

Improvements include:
* Thread safety
* ActiveRecord connection pool

Oh yay. Well it looks like the dispatching is threadsafe, but were they doing anything about ActiveRecord's threadsafety? I'm rusty on my multithreading but I seem to remember there being a few "big locks" in Rails.

Hammertime
May 21, 2003
stop

drjrock_obgyn posted:

Bump because Rails 2.2 rc1 is out:

Improvements include:
* Thread safety
* ActiveRecord connection pool

Is this moving in the direction of parallel database access?

drjrock_obgyn
Oct 11, 2003

once i started putting pebbles in her vagina, there was no going back

Hammertime posted:

Is this moving in the direction of parallel database access?

Well, the connection pool now allows you to do concurrent connections assuming you have a non-blocking database driver such as neverblock. Pratik from the core team put up a good blog post explaining everything:
http://m.onkey.org/2008/10/23/thread-safety-for-your-rails

lungfish
Oct 3, 2000
I just felt like popping in on this thread really quick. I have been programming in Ruby on Rails professionally since early 2005.

hmm yes
Dec 2, 2000
College Slice
Hi! Thanks for popping in.

hmm yes fucked around with this message at 05:29 on Oct 30, 2008

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I just felt like popping in on this thread really quick. Doo doop doouuu doo doo! Doo doo doo ooo doo!

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Rails programmers, I have a question:

I have 2 tables, let's say Node(number: integer, owner: string) and Link(up: integer, down: integer) where up and down are foreign keys to Node's number.

I really, really want to be able to go Node.find(x).up_nodes and get a list of Nodes back. Getting the Links back is obviously easy enough, but I can't figure out the right incantation for has_many :through and whatnot to get back a list of the Nodes themselves.

Self-referential queries with non-standard keynames have defeated me :(

skidooer
Aug 6, 2001

dustgun posted:

but I can't figure out the right incantation for has_many :through and whatnot to get back a list of the Nodes themselves.
If I understand your problem correctly, you are looking for something like this:
code:
class Node < ActiveRecord::Base
  has_many :up_links, :class_name => 'Link', :foreign_key => 'up'
  has_many :up_nodes, :through => :up_links, :source => :down_node
end

class Link < ActiveRecord::Base
  belongs_to :up_node, :class_name => 'Node', :foreign_key => 'up'
  belongs_to :down_node, :class_name => 'Node', :foreign_key => 'down'
end

Pardot
Jul 25, 2001




skidooer, (or anyone?) have you done much with couchdb since you posted about it way back when? I'm going to use it for my current project. couch potato looks cool. I like how it takes care of versioning, since you can't rely on the built in versioning if you want to keep it forever because when you compact you lose all the previous versions.

But there are like a billion of other adaptors. You wrote your own right?

I'm using merb, and I know datamapper has a couchdb adaptor, but using DM for couch seems wrong, since it's designed to solve sql problems. Maybe it's decent, I haven't tried it yet.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

skidooer posted:

If I understand your problem correctly, you are looking for something like this:
Totally worked (once I set_primary_key'd number)! I wasn't quite understanding what the :source attribute did before.

jimbroof
Sep 4, 2003

my wife drew this for me :]
is there a good reason why ruby doesn't support the ++ or -- operators or is it literally just to piss me off?

Hammertime
May 21, 2003
stop

WHORENDOUS posted:

is there a good reason why ruby doesn't support the ++ or -- operators or is it literally just to piss me off?

I have no idea of an official answer, but after a year and a half, I've decided without any justification that it's for consistencies sake.

a += 1
a += 2

vs.

a++
a += 2

Edit: Pretty much just to piss you off.

Pardot
Jul 25, 2001




WHORENDOUS posted:

is there a good reason why ruby doesn't support the ++ or -- operators or is it literally just to piss me off?

Why do you need to increment something by one? It's so rare that I've ever had to do that in ruby, but I know there would be a few valid cases.

I'm just making sure you're not writing while loop, or (god forbid) a for loop, when you have all the wonders of the enumerable mixin.

jimbroof
Sep 4, 2003

my wife drew this for me :]

Pardot posted:

Why do you need to increment something by one? It's so rare that I've ever had to do that in ruby, but I know there would be a few valid cases.

I'm just making sure you're not writing while loop, or (god forbid) a for loop, when you have all the wonders of the enumerable mixin.

i use it to keep track of different events that occur inside of my loops. for the actual loop i think i invariably use .each

edit: i do this mostly for debugging, still learning my way around the language and its 80 billion ways of doing any given task

weapey
Jun 11, 2003

stomp stomp stomp

WHORENDOUS posted:

i use it to keep track of different events that occur inside of my loops. for the actual loop i think i invariably use .each

edit: i do this mostly for debugging, still learning my way around the language and its 80 billion ways of doing any given task

Have you tried using Netbeans to debug Ruby applications? It has full breakpoint and inspection features you'd expect, and will make debugging much easier then writing your own code to figure out what's going on.

mcw
Jul 28, 2005
Thanks in advance for any advice you're able to offer. I've got a question:

Has anyone had any luck getting RoR to run on Windows Vista using either Apache or IIS 7? I'm getting HTTP 500 errors accompanied by a FastCGI crash, and nothing in the logs indicates what is causing the problem. It looks like the requests are indeed being routed to my local Ruby installation, but nothing ever comes back except for errors.

I've spent a couple evenings now trying every solution I could find via Google, to no avail. If anyone has any advice, I'd appreciate it greatly.

Pardot
Jul 25, 2001




MariusMcG posted:

FastCGI


You don't want to use fcgi. Either try passenger (if that works on windows??), or have apache proxy to mongrel. If you're just running one mongrer, you can just drop this in your .htaccess

code:
RewriteEngine On
RewriteRule ^(.*)$ [url]http://127.0.0.1:3000/[/url]$1 [P,L]
assuming your mongrel is running on port 3000.

If you're just doing this for development, don't even bother with apache or IIS, just go off the mongrel.

If you're doing this for production, I have nothing but sympathy for you. It's going to be painful. It's probably easiest to use jruby and drop it in tomcat or glassfish.

Also, whenever you install a gem, use --no-ri --no-rdoc because windows ruby is so goddamn slow.

Sharrow
Aug 20, 2007

So... mediocre.
How is Passenger? I've got a couple of nginx+mongrel apps that are about to be moved to a new system and get some more development time, so if it's as good as it sounds then switching could be pretty easy.

Hammertime
May 21, 2003
stop

Sharrow posted:

How is Passenger? I've got a couple of nginx+mongrel apps that are about to be moved to a new system and get some more development time, so if it's as good as it sounds then switching could be pretty easy.

I've run it in light production for a while without issues. I never seemed to get the memory gains that ruby enterprise edition promises, but everything was nice and snappy. I still sit nginx out front of apache.

bitprophet
Jul 22, 2004
Taco Defender
In my limited experience, Passenger is definitely better than Mongrel, including being easier to manage, and faster. I'm updating a Rails 1.2.5 site; it used to use Mongrel and is now on Passenger and there's definitely a bit of a speed increase even on our dev/staging hardware. Pretty sure we have at least one or two production sites using it now too.

Not to mention the fact that, at least where I work, they've had to constantly monitor the Mongrels with God or Monit because the Mongrels leak memory like a sieve and go down more often than a Saigon hooker :v: Passenger seems free from both these problems (given that it's an Apache module, I'd hope so...) and is easier to set up, to boot.

Amusingly the Django community's moving towards a Mongrel-esque platform (mod_wsgi) but I think it's probably more stable than Mongrel, otherwise it wouldn't be drawing people away from an entrenched Passenger-like situation (mod_python).

hmm yes
Dec 2, 2000
College Slice
Although I've said it before in this thread, I am going to give Passenger another post of support. It is easy to setup, seems to manage memory well, lets you track performance stats. After testing it out with a single production application I moved another 5 which had been running on mongrel over to Passenger.

I also use Passenger for development, because the Passenger Preference Pane just makes setting up development environments nice and easy. Yeah, I know all I had to do before was edit hosts and create a new vhost. Meh :)

Evil Trout
Nov 16, 2004

The evilest trout of them all
I recently switched Forumwarz back from Phusion to a pack of Mongrels. Phusion seemed to perform more or less the same from a memory standpoint but I hated how I couldn't hot deploy safely.

With a pack of Mongrels, you can do a rolling restart so that your app never goes down while pushing updates (since Nginx can proxy to the other mongrels.) With Phusion, your only choice is to touch the tmp/restart.txt, where it shuts down all processes and starts up again, preventing any requests from completing for up to 30 seconds. My users definitely noticed that!

mcw
Jul 28, 2005

Pardot posted:

If you're just doing this for development, don't even bother with apache or IIS, just go off the mongrel.

That certainly makes sense, and thanks very much for the recommendation. I've been an amateur PHP developer for years, always working on a hosted server where I never had to worry about the web server; and my experience with RoR thus far has been educational about more than just Ruby or Rails. The Apache stuff has been frustrating, but also interesting and informative; and it's important to me to know not only how to get this working but also why the solution I adopt is the best one.

With that said: After reading your very helpful post, I found this excellent article, which may be useful for anyone that wants to set up a Mongrel cluster or wants to know more about why it's a better solution than FastCGI in this case. I don't have any professional experience with this platform yet, so for the time being, any information I can find is immediately fascinating.

Tonight I'll work on implementing your Mongrel suggestion, and will also take a look at Passenger. Thanks!

palatka
Apr 4, 2003

by Ralp
Hey guys, I am working on my first Rails project and I've encountered a snag. I am working on a form for a model that has many models which in turn have many models. So I have like a one-to-many-to-many relationship (or a has_many :through). The only thing solution I can come up with is to number everything (http://pastie.org/318157) but this is neither convenient nor elegant. Anyone know a better way?

bitprophet
Jul 22, 2004
Taco Defender

Evil Trout posted:

your only choice is to touch the tmp/restart.txt, where it shuts down all processes and starts up again, preventing any requests from completing for up to 30 seconds. My users definitely noticed that!

What do you mean by "completing"? And I don't think I've ever seen an Apache reload or restart take longer than perhaps five seconds; are you saying it takes Passenger 30 seconds to actually spool up its Ruby processes? :psyduck:

HIERARCHY OF WEEDZ
Aug 1, 2005

bitprophet posted:

What do you mean by "completing"? And I don't think I've ever seen an Apache reload or restart take longer than perhaps five seconds; are you saying it takes Passenger 30 seconds to actually spool up its Ruby processes? :psyduck:

Based on my experience, this is essentially accurate. It also takes about 30 seconds to hit a site after something like 2 minutes of no one accessing it. Phusion Passenger is absurdly slow and no amount of tinkering with the configuration seems to be able to ameliorate it.

bitprophet
Jul 22, 2004
Taco Defender

Panic! at the Fist Jab posted:

Based on my experience, this is essentially accurate. It also takes about 30 seconds to hit a site after something like 2 minutes of no one accessing it. Phusion Passenger is absurdly slow and no amount of tinkering with the configuration seems to be able to ameliorate it.

What kind of site are you running with it? The one I've been updating (which isn't terribly efficient either, and is Rails 1.2-based) loads pretty quickly after e.g. /etc/init.d/apache2 restart.

Hammertime
May 21, 2003
stop

Panic! at the Fist Jab posted:

Based on my experience, this is essentially accurate. It also takes about 30 seconds to hit a site after something like 2 minutes of no one accessing it. Phusion Passenger is absurdly slow and no amount of tinkering with the configuration seems to be able to ameliorate it.

There's something seriously wrong with your phusion deployment.

I've had to benchmark phusion for a multi-app site (40 apps were used to test). Spool up time from scratch was always in the range of 2-5 seconds.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I finally took the plunge and started teaching myself Rails a few days ago -- my dad wanted me to design him a simple website, and since I'm equally inexperienced in just about all webapp frameworks (except for Apple WebObjects, which I know better than I ever wanted to know :gonk: ), I decided RoR was the one I wanted to pick up. I'm loving it so far, and I've been trying to immerse myself in "best practices" out of the box, and I'm now in a situation that's probably simple but I'm not sure exactly what's best to do here.

I decided that I wanted to ERB-ify my stylesheets, so that I could use variable substitution for common color and size constants instead of repeating myself everywhere. Using some examples on the web, I cobbled together a StylesheetsController and routed it so that /stylesheets/*.css renders one of my /app/views/stylesheets/*.css.erb files, and that works. (It doesn't need to be anything RESTful that makes use of the model -- some examples showed how to incorporate user settings into the CSS, but I don't need that.)

My question is, where's the best place to put those constants so that I can refer to them in my various .css.erb files? I don't want to define them just in a <% %> block at the top of the stylesheet since they're site-wide and should be used in multiple stylesheets (and, actually, I'd like to be able to refer to them elsewhere as well, say in JavaScript), and the opposite extreme of dumping them in environment.rb just "feels wrong" to me.

Right now, I've dropped them into application_helper.rb and other *_helper.rb files as methods prefixed with css_* so they don't conflict with anything else in my app (I had to use methods because constants don't seem to get picked up properly), and that's working, but it seems like there should be a cleaner solution here.

(Ruby 1.8.6, Rails 2.1.2)

Hammertime
May 21, 2003
stop

Flobbster posted:

I finally took the plunge and started teaching myself Rails a few days ago -- my dad wanted me to design him a simple website, and since I'm equally inexperienced in just about all webapp frameworks (except for Apple WebObjects, which I know better than I ever wanted to know :gonk: ), I decided RoR was the one I wanted to pick up. I'm loving it so far, and I've been trying to immerse myself in "best practices" out of the box, and I'm now in a situation that's probably simple but I'm not sure exactly what's best to do here.

...


That's a pretty cool/crazy undertaking (in a good way).

You've got a couple of choices I can think of:
- YAML file that gets loaded in environment.rb and exists as a hash in the global name space
- Database rows? Not as good as the yaml file really.
- Lib files? Reasonable but loaded yaml is more elegant.

Small note: make sure to turn on page caching for the stylesheets to ensure you get the best of both worlds, flexibility without the performance hit.

The yaml loading can be achieved through something similar in your environment.rb file:

code:
require 'yaml'
CSS_CONFIG = YAML::load(File.open("#{RAILS_ROOT}/config/css_config.yml"))
References can then be pulled through

code:
background-color: <%=CSS_CONFIG["secondary_main_color"]%>
You could also "helperize" the calls to abstract it by a degree (and clean things up a little) by declaring an application helper method for get_css_property.

code:
def get_css_property_thing propery_name
  CSS_CONFIG[property_name]
end
I don't think what I'm suggesting is ideal, but that's all I can think of for the moment ;)

manero
Jan 30, 2006

Hammertime posted:

Small note: make sure to turn on page caching for the stylesheets to ensure you get the best of both worlds, flexibility without the performance hit.

Yeah, you'll want to cache the gently caress out of your CSS files. Make sure you compute them once, and once you deploy to production, make sure that nginx/apache or whatever is actually serving them. You don't want to hit your app to generate CSS on every request.

You could also use something like Sass:

http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html

jonnii
Dec 29, 2002
god dances in the face of the jews

Flobbster posted:

stylesheet stuff

You might want to take a look at sass (http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html).

Pardot
Jul 25, 2001




jonnii posted:

You might want to take a look at sass

And while you're learning SASS, learn haml! Haml is the best.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

jonnii posted:

You might want to take a look at sass (http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html).

Thanks for this! I'd seen something about it briefly when I was searching for a solution to my problem, and I was initially reluctant to learn "yet another language", but it looks like this pretty much does exactly what I need without the effort of reinventing the wheel.

Since none of my stylesheets actually need to be dynamic on the server -- I'm just using substitutions as a time-saving/bug-preventing measure -- then it looks like what I should do is just use Sass during development and then have a rake task generate the flat CSS for deployment. Then I don't have to deal with the caching issue at all.

Pardot posted:

And while you're learning SASS, learn haml! Haml is the best.

One step at a time :)

HIERARCHY OF WEEDZ
Aug 1, 2005

bitprophet posted:

What kind of site are you running with it? The one I've been updating (which isn't terribly efficient either, and is Rails 1.2-based) loads pretty quickly after e.g. /etc/init.d/apache2 restart.

Rack-based Sinatra. No more than 300 lines of code, and nothing to warrant the spool-up times that I was getting. I switched to Lighttpd proxying out to Thin and now site loading is near instantaneous.

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender

Panic! at the Fist Jab posted:

Rack-based Sinatra. No more than 300 lines of code, and nothing to warrant the spool-up times that I was getting. I switched to Lighttpd proxying out to Thin and now site loading is near instantaneous.

Welp, my experiences (multiple production apps) and Hammertime's (???) would suggest your scenario was an aberration of some kind, although I don't know how different Sinatra is from Rails (i.e. perhaps there's some bizarre incompatibility that causes it to run poorly on Passenger).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply