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
Scarboy
Jan 31, 2001

Good Luck!

ANAmal.net posted:

I'm really not a fan of Rails for the most part, but sticking to the thread topic, I will say that the logging (especially in development mode) is the most thorough I've ever seen. It's wordy as hell, but pretty much anything you would ever need is in there, provided you can grep your way to it.

Breakpoints and the Script Console are pretty neat, too. I like that they made RoR apps as easy to debug as they are to program in the first place.

Agreed, I usually tail the development log all the time and it's incredibly useful. It really does show you everything.

Adbot
ADBOT LOVES YOU

Scarboy
Jan 31, 2001

Good Luck!

MrSaturn posted:

Hey, a rails question!

so I'm trying to create a new model in my application. It's going to be a hobo model, which I've created in the past. For whatever reason, I can't get
code:
rails script\generate hobo_model blogpost
to do anything!

It just outputs like this:
code:
c:\ruby\rails_apps\myapp>rails script\\generate hobo_model blogpost
      exists
      create  app/controllers
File exists - script\\generate

c:\ruby\rails_apps\myapp>
note I'm running this in windows, and I have run use_ruby.cmd, so I'm in the rails environment, or whatever.

What am I doing wrong?

Why are you prefixing script\generate by rails? It should be ruby if anything.

Scarboy
Jan 31, 2001

Good Luck!
Here's a question because I've never messed with this before. I have a method_missing method in my ActiveRecord Model that intercepts two kinds of dynamic method calls. It does this well and everything is fine and dandy, however, all the other dynamic methods that ActiveRecord uses are not recognized now. If I get no result how do I call ActiveRecords base method_missing to do whatever it has to do or raise exceptions?

Scarboy
Jan 31, 2001

Good Luck!

skidooer posted:

Call super to pass it up to the superclass. For example:
code:
def method_missing(symbol, *args, &block)
  whatever_you_need_to_do(symbol, *args, &block) || super
end

Strange, I tried just that and I don't think it worked. I'll try again, maybe I hosed something up. This is what I get for implementing permissions as an quasi bitfield in the database.

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.

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.

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.

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

Scarboy
Jan 31, 2001

Good Luck!

Al Azif posted:

I've been using Ruby for a while now, but this is my first foray into Rails (I'm a big fan of Camping, but past a certain size Camping apps get difficult to handle).

I want to be able to do this in a controller method:

code:
def index
  @orders = @user.orders
end
instead of this:

code:
def index
  @user = find_user
  @orders = @user.orders
end
Where find_user returns the user object for the current session. I think I want this for every action on every controller. Having to stick find_user in every controller method isn't very DRY, right?

before_filter :get_session_user

Then in application.rb make a private method that does @user = find_user.

Adbot
ADBOT LOVES YOU

Scarboy
Jan 31, 2001

Good Luck!

atastypie posted:

I find my helpers are generally empty, with things like this going in my model:

code:
def full_name
   self.first_name + " " + self.last_name
end
Is this something that should be a helper? What is the rule of thumb for whether something should go in the helper instead of the model?

That's definitely content for the model, your helpers should be used moreso for html junk that you repeat over and over again that doesn't really fit into partials.

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