↓ Archives ↓

Category → code

Using restful_authentication on heroku cloud hosting

A few days ago I began setting up a rails app that was in need of some user authentication. A friend of mine recommended looking at @technoweenie’s restful_authentication plugin and I already had messed around with heroku’s hosting service. Now it was time to combine the two.

I initially installed the restful_auth plugin using the ‘git clone’ method and my app worked perfectly fine on my local machine. However, when I uploaded the app to heroku, I was hitting a few errors. The first error was that my app was failing to launch because it could not find a const named ‘User::Authenticated’ … how’s that possible? I installed the plugin , shouldn’t it just know where to look for it? Well it appears that if you use the ‘git clone’ method to install the plugin, it will not work on heroku. You must install the plugin by running ’script/plugin install git://github.com/technoweenie/restful-authentication.git’. This will put all the pieces in the correct place. ALSO, be sure to change the name of the folder downloaded to ‘restful_authentication’ .. that is … change the hypen to an underscore. Once I changed that, I re-launched my app on heroku using the command ‘heroku restart’, and I hit a (NameError). Seems the ’script/plugin install’ command didn’t create an file called user_observer.rb that should be placed in the models directory. I’m not sure if this is a bug at this point but this is the workaround I used:

drop a file named user_observer.rb in your /app/models/ directory and put this code in it:

class UserObserver < ActiveRecord::Observer

def after_create(user)

UserMailer.deliver_signup_notification(user) if user.not_using_openid?

end

def after_save(user)

UserMailer.deliver_activation(user) if user.recently_activated? && user.not_using_openid?

end

end

Once I had this file in place, my app launched successfully and now included full user authentication.

YAY!

Installing MySQL Ruby gem on SnowLeopard

In my efforts to teach myself Ruby on Rails I ran into a bit of a snag installing the ruby mysql gem. After doing a bit a research I finally found this helpful bit:

http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/

Following these steps fixed the issue. Weeeee!!!



			
		

Not seeing NSLog messages after using NSPipe?

Yesterday I was working on some code that made use of NSTask and  ran into a tiny, yet annoying, issue. Essentially the code block I was working on would search a directory on the machine and return an array of paths to items which matched the results of the call to the ‘find’ tool. The only problem I found is that when I called

[task setStandardOutput: pipe];

The results from the ‘find’ command were dumped in the console.app and not in the debugger. After a little investigation, I realized I simply was just missing this call:

[task setStandardInput:[NSPipe pipe]];

After making this adjustment, NSLog was now appearing back in Xcode’s debugger/console. Yay!
Here it is in action:


#import "FileFindAppDelegate.h"

@implementation FileFindAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

[self findFiles];

}

-(void)findFiles
{
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];

NSArray *arguments = [NSArray arrayWithObjects:@"-c", @"/usr/bin/find /Users/jeffsoto/Desktop/Files -name *title*", nil];
[task setArguments: arguments];

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task setStandardInput:[NSPipe pipe]];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];

NSArray *array = [[NSArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]];

NSLog(@"Found %i matching files", [array count]-1);

int i;

for(i=0; i < [array count]-1; i++)
{

NSLog(@"Found this path %@", [array objectAtIndex:i]);
}

}

[task release];
[string release];
[array release];

@end