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
SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Disclaimer: Very new to RoR.

I've been building a small project recently and have been using migrations to build my database since apparently it's the best way to do it (?) and I'm trying to get used to The Rails Way. I realized that a migration I just created to change a field was pretty stupid so I wanted to roll back to the version beforehand. Of course, being the idiot that I am I just had to write this code...

code:
class ChangeDateToDatetime < ActiveRecord::Migration
  def self.up
    change_column :releases, :created_at, :datetime, :default => Time.now
  end

  def self.down
    raise ActiveRecord::IrreversibleMigration
  end
end
So no rolling back for me. :downs: My question is, how do I do this manually and cleanly? I tried commenting out that exception and running rake db:migrate VERSION=3 (the above file is 004_...) but nothing appears to have happened. Should I delete the entire migration file, manually editing the version number in the scheme_info table and then running rake db:schema:dump? Or will this have undesired consequences? Thanks.

Adbot
ADBOT LOVES YOU

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Hammertime posted:

Oh, and assuming this is a pre-production system. Don't bother creating separate migration files for an alter column. It's easier to migrate back to version 0, change the table declaration to include the column, and rake it back to the latest version. Before you actually push the system live, the practice is to group all the migration files together into a single file (not including sample/starting data if you have any). Ideally there's a migration file for each version of the system that gets pushed into production, having separate migration files for development is just a temporary measure.

Okay, I'll probably just futz around with it to get it back to normal, since this is only development, not production.

jonnii posted:

What was the column before hand? Were you just adding the constraint?

I changed it from :date to :datetime and added the default value. Neither were necessary.

Grob posted:

This can actually be dangerous unless you are the only person working on the project. If multiple people are checking out your source, going back and editing earlier revisions is sure to ruin their day :) Just a warning for the new guys.

Duly noted. This is currently just a personal project without source control :clint: but I'd like to add another developer or two and SVN if this ever sees the light of day.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Is either one of acts_as_searchable or acts_as_ferret inherently better than the other?

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Embarrassingly retarded question... I can't believe I can't figure out the answer to this on my own. Imagine I've got something like the following:

code:
@posts = Post.find(:all)
Which then gets passed to the view, yadda yadda yadda, this is all basic stuff. But what if @posts is empty (in this case there's no data) and I want to alter the view accordingly. I thought it would be a matter of doing something like the following:

code:
<% if @posts.nil? %>
  <p>No posts!</p>
<% else %>
  # Loop through @posts
<% end %>
But apparently not. Oh god, how do I do this? Put me out of my misery.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
:ssj: Why didn't I think of that? I tried @posts.length and @posts.count.

Thanks.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Grob posted:

Actually @posts.length should work too. @posts.size is equivalent, so I'm not sure why that failed!

Hmm, so it does, guess I forgot what I tried. It all seems so obvious now.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
I've got a controller set up like this:

code:
def method1
  # Does some processing then...
  redirect_to :action => "method2"
end

def method2
  if request.xhr?
  elsif request.post?
  else
  end
end
Basically, I'm trying to determine the entry point for method2 (which can also come from the browser). Obviously I know about the request object, but is there any way I can tell if method2 was entered from a redirect?

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
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.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
What would be the sanest way to add a "global" variable accessible by all controllers/views in an app? At the moment I've just got a method in the application helper that returns the variable but I was wondering if there was a more "rails" way to do this.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Just a constant, nothing fancy.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Can anyone tell me why this WON'T loving INCREMENT?

code:
    @item = OrderItem.find_by_access_key(@id)
    if @item == nil
      redirect
      return
    end
    
    @item.increment!(@item.collected)
collected is an int field in the order_item table defaulting to 0 (though I've manually set it to other values with no success). @item is a valid object.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Hammertime posted:

Based on the API source, I believe it's expecting the name(or maybe the symbol) of the attribute.

Try: @item.increment!('collected')

Motherfucker. Thanks a lot.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
How do I check my app's compatability with Rails 2? I was under the impression that 1.2.6 would show deprecation warnings, however, uhh... where does it show them? I can't find anything in the development.log or in the command line server output.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
I thought stuff that has been moved to plugins (pagination, some javascript helpers which I'm using) would show deprecation warnings. They're certainly noted as such in the documentation.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
So it looks like the acts_as_taggable gem is broken in Rails 2 due to the push_with_attributes method being shitcanned. What's the quickest way I can get tagging support back without loving with my app too much? I looked at acts_as_taggable_on_steroids but it hasn't been updated in two months and based on the comments on that page it may be pretty buggy. All I want is a gem/plugin that's updated regularly and works with Rails 2.

gently caress, I was so close to having my app all moved over. :(

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

atastypie posted:

You could use acts_as_taggable_on which offers the same features as on_steroids and the ability to add tags based on the model (like User) and contexts (like Interests, Bookmarks, etc.). If you don't want to use contexts, you can set it to :tags and it will basically be a drop in replacement for on_steroids.

Okay, say I go with this. How do I... finagle it in to my app? I've got a migration that created the old structure for tags, but what's the best way to pretend that never existed?

I think this goes to show how little I really understand migrations. It's my understanding that it's meant to demonstrate a series of steps that represent the state of the database schema. But what happens when you want to, say, roll the app out and freeze the schema? Is there a way you can roll all your migrations in to one and then start writing new migrations? Or what if you need to make large scale changes like I do? Is my only option to write a migration which directly reverses a previous migration? :psyduck: I guess this doesn't make a whole lot of sense to me now because I'm the sole dev of this app but I guess how I can see it would make an environment with several devs easier.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
M-M-M-Mega question post.

Is there an easy way to test ActionMailer or am I going to have to wait until this hits the production server? For the record, I'm developing on a Mac OS X and apparently I have /usr/sbin/sendmail available. I tried following http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer but mongrel made the complaint "environment.rb:47: uninitialized constant ActionMailer (NameError)" when I tried to stick some of the config stuff in there. I'm running Rails 2.0.2 and imagine this has something to do with it. On the plus side, the development.log showed the email being "sent" and everything looked fine. :shobon:

Is there any application level logger plugins floating around? Basically, all I want to do is log when a few select actions are hit for dealing with user problems. Would I be better off just rolling my own?

Next question... What would be my best hosting choice at the moment? I'm really tossing up between Media Temple or a VPS. Both have their pros and cons.

MT takes a lot of the hassle out of management and the price for the base level grid service seems reasonable for the space and bandwidth. On the other hand, it only comes with a 64 MB Rails "container" which, from my understanding, would result in some pretty crap performance. To up this to 256 MB costs an additional $25/month which ends up making it a fairly expensive $45 a month (for a project I'm funding out of my own pocket).

If I go with a VPS I'm assuming I have to do all the management for myself, and quite frankly, I know nothing about tuning a Rails server. On the other hand, I could probably get a better deal in terms of resources from one of these.

Help, goons!

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Austria posted:

Slicehost

They look pretty good price-wise, but sparse feature-wise (I guess there's a pretty obvious correlation there). I'll definitely keep them in mind.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

Austria posted:

What features are you looking for?

Their control panel is amongst the nicest I've seen for a VPS. They make it easy to get your system running (you can get a working Rails stack in a matter of minutes), keep it running and get it running after you gently caress up (rescue console, root password recovery, AJAX console, etc).

Yeah, I guess I'm stuck in the days where I ran everything through WHM/cPanel, which was 5 to 6 years ago (seriously, I haven't considered hosting since then). I'm supposed to be a professional these days so I guess I should suck it up and act like it. Sorry, moment of introspection. :)

quote:

Also, ignore most hosts' disk and bandwidth allowance. Almost all of them oversell, including (mt).

I legitimately can't in this case. I need the host to be able to deliver on their bandwidth promises. I'm going to be pushing files up to 100 MB back to customers, and if I can't, for whatever reason, I lose money.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Anyone have any more rails host recommendations?

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
Okay, so I've just "deployed" my first application, an I thought I'd share some of the things I've learned.

1) Slicehost seems pretty reasonable so far. No initial set up issues and I've only had to reimage once so far. The guides are mostly useful too.

2) I need a better way to deploy. I'm guessing SVN + Capistrano are the way to go about this. The way I just did it was to literally copy across my entire application directory, and I ran in to the following problems:
  • I set ENV['RAILS_ENV'] ||= 'production' in environment.rb. It says do that if you can't do it the better way, but in typical Rails fashion it doesn't tell you what the better way is? :confused:
  • I went to load the DB schema using rake db:schema:load but this insisted I was still in development mode and tried to create the tables in _development. In the end I had to create that database, run rake, dump the contents, create _production and load the dump. gently caress that, I nearly tore my hair out.
  • I'm using Apache to proxy requests to a Mongrel cluster. Had to run stop/start after setting up the vhost for this, reloading doesn't work.

3) Fresh environments reveal deficiencies in my code. :)

Anyone have any other advice they can offer?

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
I guess it's not going as entirely smoothly as I hoped. For some reason, the live app is working differently to the app on my dev machine. This is absolutely baffling to me since I'm using the same version of Rails and MySQL on both. Is there any logical reason for this?

I think I'm going to follow jonnii's advice because I'm getting too frustrated looking at this today, so I'll re-image tomorrow and try Nginx and Capistrano.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

jonnii posted:

what kind of differences? why not try running your app locally in production mode.

Just did this because I can't let it go and get to bed. Part of the live app is ignoring that a field is defined as :boolean (which treated as a TINYINT(1) in MySQL). If you print it it'll just show 0 or 1, where on the dev app it'll show a nice false or true. I've also got a method to toggle it, which looks like this:

code:
  def toggle
    @item = Item.find(params[:id])
    @item.revoked = params[:value]
    @item.save
    redirect_to ...
  end
Where :value is just passed in the URL as true or false, however once again, on the dev server this is working fine but on the live server it does nothing.

What confuses me most is I've used the boolean type in another place as a very similar way, and this works fine on the live server. :confused: There's absolutely no differences in the code or DB structure these things are using - the live one is generated from the dev one.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.

jonnii posted:

are you using the same version of mysql?

Yes, 5.0.45 on both.

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
I've encountered a bit of a problem with sending out emails to multiple recipients (a mailing list, not spam). Basically, from what I've read it can be done two ways.

#1
code:
  # Controller
  @list = Recipient.find(:all)
  Mailer.deliver_mailing(list, "some text from somewhere")

  # My ActionMailer instance
  def mailing(list, text)
    from "noreply@mydomain.com"
    subject "Mailing List"
    list.each do |recipient|
      bcc << recipient.email
    end
    body :text => text
    content_type "text/html"    
  end
#2
code:
  # Controller
  @list = Recipient.find(:all)
  @list.each do |recipient|
    Mailer.deliver_mailing(recipient, "some text from somewhere")
  end

  # My ActionMailer instance
  def mailing(recipient, text)
    recipient recipient.email
    from "noreply@mydomain.com"
    subject "Mailing List"
    body :text => text
    content_type "text/html"    
  end
From what I understand both methods have their pros and cons. I believe #1 to be faster, but the view is the same for every recipient. Conversely, #2 is going to be slower, but I could do stuff like add body :recipient => recipient and then in the view have access to stuff like <%= recipient.name %> if I wanted to address the mailout personally.

Is there any way to get the advantages of both?

Adbot
ADBOT LOVES YOU

SeventySeven
Jan 18, 2005
I AM A FAGGOT WHO BEGGED EXTREMITY TO CREATE AM ACCOUNT FOR ME. PLEASE PELT ME WITH ASSORTED GOODS.
I know Hobo is mentioned in the first few posts but has anyone done anything with it since? I thought I'd have a go at rewriting an existing Rails app with it to add some functionality (users and permissions) and to fix some problems with the old app. The problem I'm facing now is there's, as far as I can see, no documentation whatsoever for recent iterations of DRYML. Does anyone know if there is any reference at all?

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