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
HIERARCHY OF WEEDZ
Aug 1, 2005

gently caress that HTML poo poo, Haml is where it's at.

quote:

The most basic element of Haml is a shorthand for creating HTML tags:

code:
  %tagname{ :attr1 => 'value1', :attr2 => 'value2' } Contents
No end-tag is needed; Haml handles that automatically. Adding class and id attributes is even easier. Haml uses the same syntax as the CSS that styles the document:

code:
  %tagname#id.class
In fact, when you‘re using the <div> tag, it becomes even easier. Because <div> is such a common element, a tag without a name defaults to a div. So

code:
  #foo Hello!
becomes

code:
  <div id='foo'>Hello!</div>

There's a shitload more, including this as prepending a document with the XHTML 1.1 Doctype:

code:
!!! 1.1

Adbot
ADBOT LOVES YOU

HIERARCHY OF WEEDZ
Aug 1, 2005

leedo posted:

...and replace it with another lovely templating language :waycool:

Okay, outside, right now, let's go :colbert:

I'm seriously addicted to Haml and Sass. It's almost as fast as ERB, looks beautiful, saves me typing (except for element attributes, but that's trivial), and is easier to read. Sass is genius - variables in CSS should have existed from the beginning.

In any event, here are some other things I'm in love with:

http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle - Heckle - This testing utility mutilates your code to see if it will still pass its tests. If it does, there may be something you're not testing completely. It breaks on some things (like any code that sends conditions to the DB), but otherwise is awesome to watch.

http://chneukirchen.org/blog/archive/2007/01/announcing-test-spec-0-3-a-bdd-interface-for-test-unit.html - test/spec
Beautiful, simple-language tests.
code:
	def test_validate
		assert_equal products(:version_control_book).price, @product.price
		@product.price = 0.00
		assert !@product.save
		assert_equal 1, @product.errors.count
		assert_equal "should be positive", @product.errors.on(:price)
	end
becomes

code:
	specify "should be logically valid" do
		@product.price.should.equal 29.95
		@product.price = 0.00
		@product.save.should.equal false
		@product.errors.count.should.equal 1
		@product.errors.on(:price).should.equal "should be positive"
	end
On top of that, specifications can be written in YAML and translated into Ruby code. See this post on Err the blog.

HIERARCHY OF WEEDZ
Aug 1, 2005

enki42 posted:

What the gently caress? This seems like a lovely and backwards way of doing things. Is it impossible to do any sort of static analysis in Ruby to get actual coverage instead of changing poo poo and waiting for it to break?

You mean code coverage? Like rcov?

And regarding Haml - you can use all HTML elements. Using semantically incorrect divs is the fault of the programmer.

HIERARCHY OF WEEDZ
Aug 1, 2005

Mr. Wynand posted:

Yes Rails is all sorts of <3 and puppies, but there are more then a few things about it that make you want to run up a wall in anger when you have to deal with them.

You know what's fun? Migrating a database that halfway through used a plugin that isn't installed anymore.

HIERARCHY OF WEEDZ
Aug 1, 2005

This isn't a Rails question, but a Ruby question.

There's some code I want to use in a project, stuff I got off of RubyForge but didn't come in a gem or anything. What's the 'proper' way to put it in a project of mine? I'd imagine stuffing it all in a 'lib/', pushing that directory onto my load path, and requiring them would work - but what if those projects update? Just replace the files in lib?

HIERARCHY OF WEEDZ
Aug 1, 2005

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

HIERARCHY OF WEEDZ
Aug 1, 2005

freeb0rn posted:

The or operator (||) in Ruby can work like this.

:doh: 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.

HIERARCHY OF WEEDZ
Aug 1, 2005

What's a good way to figure out which submit button on a form was clicked if all of them have the same name?

HIERARCHY OF WEEDZ
Aug 1, 2005

I'm trying out Aptana+RadRails for a project, and I'm curious. autotest works fine when saving the actual models/views/controllers, but won't activate if I save a test file. Is there any way to get autotest to run a file in /test/ when it gets saved?

HIERARCHY OF WEEDZ
Aug 1, 2005

And another question - how the hell do you deploy to a subdomain?

I've tried installing Typo to blog.mysite.com. So I'd have something like ~/sites/blog.mysite.com/public symlinked to ~/public_html/blog and a subdomain created which points to that directory. First I had to figure out the trailing slash problem (the difference between mysite.com/blog/ and mysite.com/blog) but now that that's working, going to blog.mysite.com doesn't work at all. There's got to be a way to fix this without resorting to site-specific routing stuff, right?

HIERARCHY OF WEEDZ
Aug 1, 2005

Grob posted:

Chiming in to say that I'm quite experienced with Ruby and Rails after working with it full time for the last year, so I'll gladly answer any questions anyone might have.

My project is a web-based role playing game based on Internet culture. It's got over 100 models and uses a lot of awesome Ruby meta-programming tricks. It uses Haml for the templates and Sass for the stylesheets.


What web server are you using? Because deployment changes drastically depending on this. For example, in Apache2 I'd set up a NamedVirtualHost to whatever directory you're running your Typo install out of (forget the symlink).

My host (Site5) is using Apache, but I'm not sure how much control I have over it.
EDIT: Yeah, I can only edit .htaccesses.

HIERARCHY OF WEEDZ fucked around with this message at 16:22 on Sep 5, 2007

HIERARCHY OF WEEDZ
Aug 1, 2005

How would one deploy a common library to all sites on a server? I ask the question this way because I'm coming from ASP.NET, where if we updated something in a global utilities library, we could just copy the DLL to separate projects, or even better, import it server-wide. I'm guessing it has something to do with plugins and maybe using capistrano to update the plugins for each site in a special deployment, but beyond that I wouldn't have any ideas.

HIERARCHY OF WEEDZ
Aug 1, 2005

Ambition is getting more awesome:

quote:

Ambition has gone from generating generic SQL to respecting your database of choice (as long as it’s MySQL or PostgreSQL). [...] And because Postgres supports case insensitive regular expressions, so do we:

code:
User.select { |m| m.name =~ /chris/i }
SELECT * FROM users WHERE users."name" ~* 'chris'

And some vague benchmarks:

code:
# Ambition 0.1.0
                           user     system      total        real
simple select          7.030000   0.020000   7.050000 (  7.052899)
dual select            8.050000   0.010000   8.060000 (  8.094917)
join select            7.890000   0.030000   7.920000 (  8.003906)
dual select w/ sort   13.390000   0.040000  13.430000 ( 13.529581)
dual select w/ stuff  13.600000   0.050000  13.650000 ( 14.107565)
it's complicated      16.030000   0.070000  16.100000 ( 16.213238)

# Ambition 0.2.2
                          user     system      total        real
simple select         0.910000   0.010000   0.920000 (  0.921048)
dual select           1.380000   0.010000   1.390000 (  1.398235)
join select           1.950000   0.020000   1.970000 (  1.981603)
dual select w/ sort   1.960000   0.000000   1.960000 (  1.964018)
dual select w/ stuff  2.080000   0.010000   2.090000 (  2.111435)
it's complicated      2.820000   0.000000   2.820000 (  2.831330)

HIERARCHY OF WEEDZ
Aug 1, 2005

I am extremely slowly picking my way through deployment with Capistrano, and I've already hit a snag. The (really shittily sparse) manual tells you to create a Capfile for a project with `capify ~/project`. What I don't understand is, this creates a config/deploy.rb file in your project. But - Capistrano is supposed to be getting the latest project from Subversion. How come the deploy.rb is linked to a checkout of the pristine code?

I'm sorry if I'm being difficult to understand - it just seems like there's a disconnect there. If you have a deployment system that's looking to checkout your code from source control and place it on a server, how come it's not completely removed from the code?

HIERARCHY OF WEEDZ
Aug 1, 2005

Yossarian22 posted:

You theoretically dont need to commit your deploy.rb file to your repo to get it to work. Cap deploy reads off your local copy so whatever is in your local deploy.rb file is what gets executed.

Right. But what I'm asking is why is there a deploy.rb file at all? Why aren't the deployment instructions completely independent of whether or not there's a copy of the source code checked out?

HIERARCHY OF WEEDZ
Aug 1, 2005

Grob posted:

The way Capistrano works is that it tunnels through SSH and executes a series of instructions on a remote machine. It needs to be run FROM somewhere, usually on a development machine that has a copy of the source locally.

If it were a server process you could just notify it to deploy itself, sure.

The deploy.rb is part of the instructions you're running that in turn execute remote SSH commands.

What I'm trying to say is, why can't we have something along the lines of a deployments directory, that has deploy.rb's and subdirectories for all the applications we can deploy, which is completely unrelated to any local checked out copies of the source?

For example,
code:
# ls ~/Deployments
MyApp1 MyApp2 MyApp3
# ls ~/Deployments/MyApp1
deploy.rb
Since the SVN information is in the deploy.rb, there's no need to even have a checked out copy of the application available to deploy it. It doesn't even have to be on a server or anything - just a machine that has deployment recipes that may or may not also be used for development.

HIERARCHY OF WEEDZ
Aug 1, 2005

I have a rake task that is supposed to download and extract a '.zip' file. I'm running system commands, so something like
code:
`unzip -f -d #{extract_dir} #{zip_file}`
It's not portable, but I switched from zipfilesystem because every time I attempted to do the extraction with zipfilesystem, I would get an error about a corrupt archive. But now this code won't work either - the unzip command, both on my dev machine and the live server, says the archive is corrupt, which is bullshit because I can cancel the rake task and run the command it runs, and everything works perfectly.

Someone I spoke to suggested a permissions error, but I doubt I would get this message if it were a permissions error:

quote:

End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /blah/blah/blah/archive.zip or ...

Of course, that last line is also bullshit, since that's exactly where the archive is.

HIERARCHY OF WEEDZ
Aug 1, 2005

Sharrow posted:

code:
Changeset 8328

Timestamp:  12/07/07 04:34:12 (6 hours ago)
Author:     david

Message:    Tagged Rails 2.0.0

Files:      tags/rel_2-0-0 (copied from trunk)
I imagine the official announcement will be out later after all the gem servers have updated.

God, I cannot wait to start playing around with Rails 2.0. I just have to make it through finals week first :( This blog post from the Ruby on Rails blog shows a lot of the work that's been pushed into the newest release, and it all sounds really exciting.

HIERARCHY OF WEEDZ
Aug 1, 2005

I'm trying to use curl to get a better feel for this REST stuff, but any action I attempt raises an InvalidAuthenticityToken exception. I imagine I need to have some kind of session ID, but I don't know how I'd generate that from curl. Any ideas?

HIERARCHY OF WEEDZ
Aug 1, 2005

SpaceNinja posted:

This may seem like a stupid question, but how do I correctly configure database.yml? I am giving RoR development under Windows a shot, and previously I recall that the only bit of configuration I had to do was set my password to access MySQL. Now all I get is this as the default:
code:
# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/development.sqlite3
  timeout: 5000

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  timeout: 5000
Am I just being incredibly dense and missing something here? Or has this changed with Rails 2.0?


Call rails with '-d mysql' now. I think this is a bug, because just calling rails says that mysql is the default database, but we're ending up with a sqlite configuration.

HIERARCHY OF WEEDZ
Aug 1, 2005

Thoom posted:

Not a bug, it's the new default, mainly because it's easier to set up. Also, sqlite3 is installed by default on Mac OS X, which a whole lot of rails developers use.

Then there's a bug in the documentation:
code:
    -d, --database=name              Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).
                                     Default: mysql

HIERARCHY OF WEEDZ
Aug 1, 2005

Hop Pocket posted:

ferret :words:

Here's a question. No matter what gems and plugins I install, script/ferret_server never shows up for me. Instead I have to use vendor/plugins/acts_as_ferret/ferret_server. Where did that executable come from for you?

HIERARCHY OF WEEDZ
Aug 1, 2005

Okay, Site5 loving sucks. What's the latest round of suggestions for a Rails/Ruby framework friendly host -- and what's the score on hosting providers picking up on Phusion Passenger aka mod_rails?

Damnit going to have to move all my sites again grumble grumble

HIERARCHY OF WEEDZ
Aug 1, 2005

Okay, so since apparently no one is actually deploying Rails projects, I have another question :)

Say we have a User model, and a Recipe model, and Recipe belongs_to a User. If I want to retrieve the number of recipes a user has, I can do something like Recipe.count( :conditions => [ 'recipe_user = ?', user_id], :include => :user), but what if I wanted to cache that number, so it wasn't calculated every time I had a list of thousands of users? Should I just add another table column and run a rake task every 30 minutes or so that re-calculates and UPDATEs that column for the Users table? Or is there a more sensible way of dealing with this?

EDIT: Oh hey, counter_cache. Hooray! See here for details if you have the same question: http://railscasts.com/episodes/23

HIERARCHY OF WEEDZ
Aug 1, 2005

Grob posted:

No, some of us have Rails projects in production. Forumwarz, my MMO, is deployed on a dedicated host.

The technology is Nginx proxying to a pack of Mongrels.

I don't have any recommendations for small projects, but if you are doing mid-sized traffic (right now we're doing 20 dynamic rq/sec) a dedicated server is quite affordable at most hosting companies.

I just assumed that since you said you were interested in Phusion that you were working on something smaller.

Well, that's the thing. I don't have *any* projects because I don't trust myself to do deployments, and I don't do any deployments because I don't have sufficient hosting, and I don't feel it's necessary to pay out the rear end for hosting on projects that for all intents and purposes aren't valid public projects, but just me playing around with the framework. So it's a conundrum.

HIERARCHY OF WEEDZ
Aug 1, 2005

jonnii posted:

Capistrano makes deployment pretty easy. In my case I have an nginx frontend proxying to thin instances. I use god to keep the memory usage in check and backgroundrb running.

That's what I've heard, but I haven't had a chance to actually try it. That's what I'm asking. Where are people deploying their projects? Their one-off, unimportant stuff? I'm not shelling out 400 dollars a month for an Engine Yard slice. I'm still in college, you know?

HIERARCHY OF WEEDZ
Aug 1, 2005

Oooh, a VM image is a good idea. But Slicehost is looking pretty tempting. I don't want to just run Rails apps, since I'm a Merb and Camping guy, too. I have a feeling I'll get plenty of mileage out of a VPN.

HIERARCHY OF WEEDZ
Aug 1, 2005

I'm trying to throw OpenID at Sinatra, and goddamn is it annoying. The documentation comes with no examples -- which I half feel is an appropriate way to approach the subject, since it's important to understand all of the steps you're going through -- but on top of that, the library is written in a Ruby-esque way... or even at all sometimes.

code:
# File lib/openid/extension.rb, line 14
    def get_extension_args
      raise NotImplementedError
    end
Well, poo poo, that's helpful. On the plus side, I have basic authentication working, but getting SReg extension stuff -- like just a username would be nice -- doesn't seem to be happening. However, it may be the OpenID provider I'm using - Flickr through Yahoo!. Does anybody know how I can find out explicitly if Yahoo! provides an SReg implementation? I don't get anything back in the "openid.signed" param that mentions SReg.

HIERARCHY OF WEEDZ
Aug 1, 2005

So what's the buzz on Sequel? It looks really awesome but I don't hear any news about people using it in any projects.

HIERARCHY OF WEEDZ
Aug 1, 2005

Pardot posted:

I think datamapper is drawing most of the non-active record users. Of course, non-ar isn't exclusive, but sequel really seems like the 3rd party candidate.

That's bizarre; I've never found DataMapper to be that great, and the new syntax they've introduced for most of their instantisation stuff bugs the hell out of me. In addition, while the community is helpful, their documentation is really sparse. Ah well. Maybe I'll write about using both in a project soon.

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.

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.

HIERARCHY OF WEEDZ
Aug 1, 2005

Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc...

HIERARCHY OF WEEDZ
Aug 1, 2005

NotShadowStar posted:

The Rails team is doing a big bug smash push this weekend. Lots of help needed!

http://weblog.rubyonrails.org/2009/7/28/rails-bugmash

I can't wait to see the results of this. I love it when good software gets better in leaps and bounds because of the community's passion. Wish I had the chops to contribute.

HIERARCHY OF WEEDZ
Aug 1, 2005

What's the cleanest way to represent this idea?

I have a model, and different links to different actions on different controllers related to that model. It's not very RESTful, I'm afraid, but that's not the priority of the project; however it means I can't use the nice automagic RESTful URL helpers

There are two conditions, an initial condition and a secondary condition.
So if the initial condition is true, I don't want to return a link at all.
If the initial condition is false, and the secondary condition is true, then I want to return a hyperlink with text "Create Foo" and a link to FoosController#new.
If the initial condition is false, and the secondary condition is false, then I want to return a hyperlink with text "Edit Foo" and a link to FoosController#edit.

Right now I have something like this in the model:

code:
  def foo_url
    return nil, nil if self.initial_condition
    return 'Create Foo',   { :controller => :foos, :action => :new } if self.secondary_condition
    return 'Edit Foo',     { :controller => :foos, :action => :edit }
  end
And then both return values get passed to link_to in the controller. I know about link_to_if but it's still kind of unwieldy to use it.

HIERARCHY OF WEEDZ
Aug 1, 2005

I know it violates MVC, that's why I was asking. All I'm trying to do is have a list of links, each one with subtly different logic for when they should show up on a page. I finally decided upon this in the view, which I can tear out into a partial if it turns out it needs to be duplicated:

code:
<%= link_to_unless(bar.secondary_condition, 'Create Foo', { :controller => :foos, :action => :new }) do
    link_to('Edit Picks', { :controller => :foos, :action => :edit })
  end unless bar.initial_condition -%>

HIERARCHY OF WEEDZ
Aug 1, 2005

My example wasn't perfectly analogous. It would be to create a new Foo based on the condition of an existing Bar.

Adbot
ADBOT LOVES YOU

HIERARCHY OF WEEDZ
Aug 1, 2005

bitprophet posted:

Oh good, screencasts.

I love using Ruby, but it seriously irks me that the community's idea of "documentation" is one of: read a simple-rear end Hello World style README, pay money for a book, watch a (sometimes for-pay, almost always limited in scope) video, or learn the source code inside and out.

Heaven forbid the author take the time to write some comprehensive usage + API documentation so non-trivial non-common use cases aren't left out in the cold.

One of these days the Ruby and Python communities should switch places for a bit so Python can learn how to have usable test frameworks and Ruby can learn how to document their projects.

I'm not bitter, who's bitter?

Uhh, if you had gone to any of the Railscasts pages, you would see that every one has a complete transcript located on ASCIIcasts: http://asciicasts.com/episodes/209-introducing-devise

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