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

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.

Adbot
ADBOT LOVES YOU

vg8000
Feb 6, 2003

You never question Heylia's eyeballing. That's the rainman of weed right there.

MrSaturn posted:

Speaking of all this migration business, how can I use rake db:migrate to just... add a field to a table? I'm still heavily developing my application, and I often find the need to add columns (as I develop features), and I don't want to have to wipe the contents of my db each time. Often rake db:migrate doesn't seem to do anything.

code:
class Whatever < ActiveRecord::Migration
  add_column 'table', 'column', :datatype
end

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Ah, thanks!

Regarding migrations, to the naysayers, seriously, look into hobo. this is coming in the next release!

Big Big Moon
Sep 2, 2006

In other regions and restaurants it is mispronounced as General Tsao's, General Zhou's, General Tzo's, General So's, General Joe's,
Heeey, UConn CS sophomore here. Any professor/course recommendations?

Fork
Aug 5, 2004
I don't like incremental migrations during development beyond setting up the base tables. Everything evolves too quickly and a db:reset with a sql file to load isn't too painful (or load fixture data into your development database). My team is much smaller so we don't run into big problems with database clashes and just tell eachother when we've made a database change. I start using them the 'right' way when the application is in production. I figure I can live with a little inconvenience during development.

vg8000
Feb 6, 2003

You never question Heylia's eyeballing. That's the rainman of weed right there.

MrSaturn posted:

Ah, thanks!

Whoops, be sure to put that in the self.up method :shobon:

Scarboy
Jan 31, 2001

Good Luck!
You guys know you're supposed to consolidate your migrations every once in a while, right? You're probably not going to go back to that migration you were using 200 version ago or whatever.

skidooer
Aug 6, 2001

vg8000 posted:

Yeah but when you try to re-migrate from scratch, you're using [latest model] versus [older database migration] that may not be compatible anymore. He said this himself in his post.
You can redefine the model within the migration to solve that problem. Not exactly DRY, but a lot better than trying to manage versioned models in an automated fashion.
code:
class MigrationName < ActiveRecord::Migration
  class User < ActiveRecord::Base; end
end
Although I have to agree with Scarboy. If you're starting a fresh database use db:schema:load instead of starting from migration version 1.

Mr. Wynand posted:

sooner or later an if RAILS_ENV=="development" is going to slip in your code somewhere...
Why not just use a mock object?

skidooer fucked around with this message at 22:06 on Aug 10, 2007

ikari
May 17, 2003

Yeah, pretty much.

Mr. Wynand posted:

sooner or later an if RAILS_ENV=="development" is going to slip in your code somewhere...

code:
module RailsPatches
  module EnvironmentSettings
    
    def environment
      RAILS_ENV
    end
    
    %w[development test production].each do |env|
      define_method("#{env}?") { environment == env}
    end

  end
end

Rails.extend(RailsPatches::EnvironmentSettings)

>> Rails.development?
=> true

In the case that you absolutely positively unfortunately must do something like that, it reads a lot nicer and will be less of a pain if the RAILS_ENV constant is ever deprecated :)

Tandori Jones
Aug 1, 2006
Saayyyyy Whhhaaat?
I dismissed Ruby on Rails until this thread, and now I'm really liking what I see. Does anyone know of a good webhost that supports Ruby on Rails? I've checked the hosting threads, but did not see anything that really caught my interest.

dvgrhl
Sep 30, 2004

Do you think you are dealing with a 4-year-old child to whom you can give some walnuts and chocolates and get gold from him?
Soiled Meat

Tandori Jones posted:

I dismissed Ruby on Rails until this thread, and now I'm really liking what I see. Does anyone know of a good webhost that supports Ruby on Rails? I've checked the hosting threads, but did not see anything that really caught my interest.

Site5 does https://www.site5.com.

I use them for hosting and they are great. Excellent customer support, and great instructions on how to put your RoR app on their hosting.

dvgrhl
Sep 30, 2004

Do you think you are dealing with a 4-year-old child to whom you can give some walnuts and chocolates and get gold from him?
Soiled Meat
holy poo poo my first quote != edit

Pardot
Jul 25, 2001




shopvac4christ posted:

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

Haml is awesome. We use it at my company and it's just great. I wish we could use sass too, but our designers need to make changes to the css often and don't understand it :smith:

Scarboy
Jan 31, 2001

Good Luck!
Before haml existed I tried making a page with Builder because I was sick of the terrible indentation and it was a nightmare. haml looks perfect and sass looks fantastic too, I think I'm going to start using them from now on.

nebby
Dec 21, 2000
resident mog
Rails is a great webapp framework ruined by a lovely O/R framework.

Sir Chicken Caesar
Feb 19, 2005

Cock a doodle don't
Fun Shoe

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.

Fair points, I guess it's just refreshing to see a framework that even thinks about these things. They seem to be unknown subjects in the .Net world.

What about the other RAD frameworks, like Django or Zope/Plone? Do they have similar development process features?

chaosbreather
Dec 9, 2001

Wry and wise,
but also very sexual.

If I'm doing a minor little project I like to use _why's microframework Camping. It's easy as pie to then scale it up to a full blown rails project if I need the space.

skidooer
Aug 6, 2001

nebby posted:

Rails is a great webapp framework ruined by a lovely O/R framework.
I fail to see how one library can ruin another. ActiveRecord is not a required dependency. You can use whatever persistence layer you want.

vg8000
Feb 6, 2003

You never question Heylia's eyeballing. That's the rainman of weed right there.

skidooer posted:

I fail to see how one library can ruin another. ActiveRecord is not a required dependency. You can use whatever persistence layer you want.

And is Og any better? Are there any other ORMs for Ruby besides those two?

skidooer
Aug 6, 2001

vg8000 posted:

Are there any other ORMs for Ruby besides those two?
There is also ruby-sequel. I don't really see what's so terrible about ActiveRecord though.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Fork posted:

Have you tried looking at Selenium and Watir to do the type of testing your talking about? I'm personally not a big fan of that type of testing because the breakdowns usually occur on the model or controller level anyway, and like you said, it changes way too often to be of much value. Regarding testing not being worth the investment -- I have to say, I've seen some stupid things said about Rails, but that's the first time I've heard that one. I will admit it takes discipline and experience to do it correctly but it does pay off eventually and sometimes in spades.
I should probably have emphasized I was complaining about Selenium specifically, not automated testing in general.

Having said that when 60% of your code is javascript (or, more simply, most of your errors happen in the browser), the lack of proper client-side testing tools becomes a real problem and you really gotta re-evaluate your testing strategy.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

skidooer posted:

You can redefine the model within the migration to solve that problem. Not exactly DRY, but a lot better than trying to manage versioned models in an automated fashion.
code:
class MigrationName < ActiveRecord::Migration
  class User < ActiveRecord::Base; end
end

That's... actually not too bad an approach. We could even take it further and clone the whole app/models dir to db/migrations/00_migration_name/. Would bloat the gently caress out of your code base but it would be a pretty darn reliable way to have data consistency migrations that actually work.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

ikari posted:

code:
module RailsPatches
  module EnvironmentSettings
    
    def environment
      RAILS_ENV
    end
    
    %w[development test production].each do |env|
      define_method("#{env}?") { environment == env}
    end

  end
end

Rails.extend(RailsPatches::EnvironmentSettings)

>> Rails.development?
=> true

In the case that you absolutely positively unfortunately must do something like that, it reads a lot nicer and will be less of a pain if the RAILS_ENV constant is ever deprecated :)

RAILS_ENV should get deprecated and the above should be made the default. Until then you wouldn't be able to do it without breaking plugins.

At work we just made our own little loader script that loads a separate database.yml, and runs different test/env/prod configs for each developer and/or deploy target.

That actually works very well for us, but the way envs work out of the box is pretty sucky.

ikari
May 17, 2003

Yeah, pretty much.

Mr. Wynand posted:

RAILS_ENV should get deprecated and the above should be made the default. Until then you wouldn't be able to do it without breaking plugins.

At work we just made our own little loader script that loads a separate database.yml, and runs different test/env/prod configs for each developer and/or deploy target.

That actually works very well for us, but the way envs work out of the box is pretty sucky.

Yeah. The nice thing is that for a while now, database.yml has been run through ERB before being parsed. So using aliases, anchors, and mappings in YAML plus reading in other files by breaking out into ERB, you can actually do a lot of clever things with database.yml alone.

CHRISTS FOR SALE
Jan 14, 2005

"fuck you and die"

Walrus791 posted:

Whats everyone using as a Rails IDE? I just installed Apanta/RadRails for Eclipse and its looking very convenient, if a little shallow. Still more then SciTE/Notepad++, but still, a nice IDE goes a long ways.
If you have a Mac, get TextMate. I use Rails on Mac's internal Apache/MySQL and TextMate and it works wonders.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
Let's say I've got an item called a house in my database. I want a house to be able to create a room. What syntax do I have to use to get the user that created the house, given only the house object? I thought it'd be like
php:
<?
:User.find(House['user_id'])
?>
but that doesn't seem to work. I guess I don't have a grip on this yet. Help?

hmm yes
Dec 2, 2000
College Slice
edit: misread what you were trying to do :)

hmm yes fucked around with this message at 19:03 on Aug 15, 2007

Scarboy
Jan 31, 2001

Good Luck!

MrSaturn posted:

Let's say I've got an item called a house in my database. I want a house to be able to create a room. What syntax do I have to use to get the user that created the house, given only the house object? I thought it'd be like
php:
<?
:User.find(House['user_id'])
?>
but that doesn't seem to work. I guess I don't have a grip on this yet. Help?

If the foreign key to the user is called "user_id" then that should work. Is House the house object or the model name?

User.find(house[:user_id]) should work

If you have a belongs_to :user in your House model, then when you first find the house you can add :include => :user (I think that's the syntax) which will give you house[:user][:username], etc... capabilities.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
where would I put :include=>user ?
edit: see the problem here is I'm trying to set hobo's
set_creator_attr to :User.find(venue['user_id']) and I'm getting a
code:
 NameError

undefined local variable or method `venue' for Listing:Class
on this code
php:
<?
set_creator_attr :User.find(venue['user_id'])
?>

MrSaturn fucked around with this message at 19:26 on Aug 15, 2007

Scarboy
Jan 31, 2001

Good Luck!

MrSaturn posted:

where would I put :include=>user ?

Here's an example:

@houses = House.find(:all, :include => :user)

and your new favorite page:
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000992

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

Scarboy posted:

Here's an example:

@houses = House.find(:all, :include => :user)

and your new favorite page:
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000992

well the problem with that call is that I'm in a room, and I have a valid reference to a house, but not to a user. so the :include => :user part wouldn't work, right?

skidooer
Aug 6, 2001

MrSaturn posted:

well the problem with that call is that I'm in a room, and I have a valid reference to a house, but not to a user. so the :include => :user part wouldn't work, right?
Is this what you're trying to do?
code:
@user = Room.find(1).user
@user = House.find(1).user
@house = User.find(1).houses.create(params[:house])
@house.rooms.create(params[:room])
...etc...
code:
class Room
  belongs_to :house
  delegate :user, :to => :house
end

class House
  belongs_to :user
  has_many :rooms
end

class User
  has_many :houses
end

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
yeah, that's kinda like it, though the syntax is a bit different because of hobo. it turns out my problem was a mound of different things, but the eventual syntax is this:

House.find(:first,:conditions=>[ "user_id = ?", user['user_id']])


out of curiosity, would I be better of replacing my belongs_to :user to a delegate? I've never used delegate.

skidooer
Aug 6, 2001

MrSaturn posted:

yeah, that's kinda like it, though the syntax is a bit different because of hobo. it turns out my problem was a mound of different things, but the eventual syntax is this:

House.find(:first,:conditions=>[ "user_id = ?", user['user_id']])
In that case, I think you'll find this syntax is preferable:
code:
user.houses.find(:first)
 

quote:

out of curiosity, would I be better of replacing my belongs_to :user to a delegate? I've never used delegate.
Delegate just passes the message along. Essentially the same as writing:
code:
def user
  house.user
end
You probably don't want to replace a belongs_to with a delegate, but it's hard to say for sure without seeing it in context.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...

skidooer posted:

You probably don't want to replace a belongs_to with a delegate, but it's hard to say for sure without seeing it in context.

Well, a room really does only belong to a house, but hobo's user model makes it so that it verifies who can create what using user objects. This is such an odd specific problem, I really appreciate your help. I think I have it working decently for now, though. Thanks so much for your help, the hobo forums really weren't replying.

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?

AlternateAccount
Apr 25, 2005
FYGM
Have there been any quality books written on Hobo? I learn a lot better from paper than from a computer screen. I really dont want to switch browser windows all day long looking up DryML tags.

hk0
Sep 24, 2005

HO HO HO!!!

floWenoL posted:

... an example of something Ruby does that is done in Perl better.

Well, this is a just a silly preference thing, but I like Catalyst and Mason more than RoR. But maybe it's just my unfamiliarity with the RoR way.

hmm yes
Dec 2, 2000
College Slice
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.

I have a problem that I am sure is actually really simple: I want to add up and return a total price across a m2m association. Using the generic example, I want to be able to add up the total price of all Books based on an Author.

Author
habtm :books

Book
habtm :authors
t.column "price", :integer

Can anyone help me out?

Adbot
ADBOT LOVES YOU

Al Azif
Nov 1, 2006

shopvac4christ posted:

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?

Yes, and yes.

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