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
Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

phazer posted:

I will say deploying an existing rails app on Media Temple was WAY easier than dreamhost. (before i decided to restart the application)

Speaking of deployment...

I've been working on my first RoR application for the past month or so, and hope to deploy it in a couple weeks. (I haven't even approached it yet, I've been doing everything in development.)

In a couple of the RoR books I've been referring to, everything I've read makes deployment seem like so much unnecessary complexity (setting up an SVN repository, Capistrano...), and it has my eyes pretty much glazing over, though partly I'm sure because I'm not ready for it yet.

As I go back to RTFM some more, I'm hoping someone can just give it to me straight -- is it possible to deploy a site simply by uploading my app's directory tree (and the SVN stuff is just for things like managing updates/changes more easily), or do I really need to deal with all this extra cruft for even the most basic site?

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender
Using a source control system like SVN is basic development practice these days no matter what you're working in; there's really no excuse for not doing so, regardless of the size of your site. If your code's not based out of an SVN/Git/etc repo, you're doing yourself a major disservice. (Reasons include: it keeps a backup of your code for you so it's not all just sitting on your workstation or web server; it does make change sets much easier to work with; gives you a history of what you've worked on; allows for rollbacks when you break poo poo; etc)

As for deployment itself, the reason it's so complicated is because of all the moving parts involved -- the server setup (Mongrels or at least the Passenger gem for Apache), the database creation, running the migrations, copying the files, etc.

That's all basic stuff any Web app needs to run, of course, but then Rails adds more on top such as keeping multiple checkouts of your code for rollbacks and shared assets and so forth. These things are not strictly necessary, though, but I get the sense it's a Rails best practice which is why everyone does it (N.B. still learning how Rails folks do things).

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I will say deploying an existing rails app on Media Temple was WAY easier than dreamhost. (before i decided to restart the application)

Hah, yeah, dreamhost is a whole other can of worms.

I'm hoping that these hosts get their act together soon and start using Passenger. There's no reason not to at this point- it is so much better for pretty much any setup. Using a whole VPS for a toy app is overkill.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Flobbster posted:

Speaking of deployment...

I've been working on my first RoR application for the past month or so, and hope to deploy it in a couple weeks. (I haven't even approached it yet, I've been doing everything in development.)

In a couple of the RoR books I've been referring to, everything I've read makes deployment seem like so much unnecessary complexity (setting up an SVN repository, Capistrano...), and it has my eyes pretty much glazing over, though partly I'm sure because I'm not ready for it yet.

As I go back to RTFM some more, I'm hoping someone can just give it to me straight -- is it possible to deploy a site simply by uploading my app's directory tree (and the SVN stuff is just for things like managing updates/changes more easily), or do I really need to deal with all this extra cruft for even the most basic site?

You can set Cap to deploy_via :copy, which is what I recommend for the time being. I think there are a couple of plugins to capistrano which will allow you to do rsync, which would be better.

Obviously using source control and deploying from there is the way to go, but this should get you over the hump.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

bitprophet posted:

Using a source control system like SVN is basic development practice these days no matter what you're working in; there's really no excuse for not doing so, regardless of the size of your site. If your code's not based out of an SVN/Git/etc repo, you're doing yourself a major disservice. (Reasons include: it keeps a backup of your code for you so it's not all just sitting on your workstation or web server; it does make change sets much easier to work with; gives you a history of what you've worked on; allows for rollbacks when you break poo poo; etc)

Right -- don't get me wrong, I use CVS and SVN for a handful of projects I'm involved in. I guess it's just a shift from what I'm used to that I need to wrap my head around, from using source control on an already-configured site like SourceForge to maintain my code separate from where I'm developing it, versus setting up my own repository and using it to actually deploy the site to the location it's going to run from.

quote:

As for deployment itself, the reason it's so complicated is because of all the moving parts involved -- the server setup (Mongrels or at least the Passenger gem for Apache), the database creation, running the migrations, copying the files, etc.

That's all basic stuff any Web app needs to run, of course, but then Rails adds more on top such as keeping multiple checkouts of your code for rollbacks and shared assets and so forth. These things are not strictly necessary, though, but I get the sense it's a Rails best practice which is why everyone does it (N.B. still learning how Rails folks do things).

Praetorian42 posted:

You can set Cap to deploy_via :copy, which is what I recommend for the time being. I think there are a couple of plugins to capistrano which will allow you to do rsync, which would be better.

Obviously using source control and deploying from there is the way to go, but this should get you over the hump.

Thanks for all the advice, I suppose I should bite the bullet and try setting it up The Right Way from the get-go. I guess my confusion stemmed from assuming this would be like, say, PHP where I just dump the code somewhere and I'm done.

bitprophet
Jul 22, 2004
Taco Defender

Flobbster posted:

I guess it's just a shift from what I'm used to that I need to wrap my head around, from using source control on an already-configured site like SourceForge to maintain my code separate from where I'm developing it, versus setting up my own repository and using it to actually deploy the site to the location it's going to run from.

Hmm. I haven't used SF's SVN but I don't get what the difference is. Where the SVN is hosted has no bearing on any of this, so long as you are able to commit to and check out from the repository in question.

In terms of "deploying from SVN", the only difference I can think of is that you might be used to manually copying files from an SVN checkout locally, to the server, versus doing the SVN checkout on the server itself. Not really a huge leap :) and the benefit is that if you ever need to, you can connect to the server and see what SVN version is currently checked out, svn up it, or svn switch between release tags (which is what I usually do -- even wrote a plugin with Cap tasks for doing SVN "the right way" with branches/tags/deploying tags to the server/etc.)

quote:

Thanks for all the advice, I suppose I should bite the bullet and try setting it up The Right Way from the get-go. I guess my confusion stemmed from assuming this would be like, say, PHP where I just dump the code somewhere and I'm done.

Yea, I got the impression that's what you were comparing it to. PHP is the most stupid-easy deploy setup anywhere and is one of the reasons it has the popularity it does.

Unfortunately, it means you get used to that way of doing things, so anything more robust like deploying with mod_rails/mod_python/Mongrel/WSGI seems crazy complex by comparison. Trust us that these solutions are more complex because they offer more power and more flexibility, not because they suck :) (Well...Mongrel exempted...it does suck. Use Passenger/mod_rails.)

Really, PHP vs Ruby/Python is the same story on both the language and deployment fronts: PHP is "easier", but lacks a lot of the power and flexibility the others have, and in the long run is generally a lesser solution.

unleash the unicorn
Dec 23, 2004

If this boat were sinking, I'd give my life to save you. Only because I like you, for reasons and standards of my own. But I couldn't and wouldn't live for you.
What's a good way to start Windows application with a Ruby script? Like, just start Firefox for example.

Before you answer, please consider that I don't "get" OLE.


alright I found "exec".

How do I escape the space in "C:\Program Files\"?

unleash the unicorn fucked around with this message at 22:41 on Dec 14, 2008

phazer
May 14, 2003

chirp chirp i'm a buffalo

Praetorian42 posted:

Hah, yeah, dreamhost is a whole other can of worms.

I'm hoping that these hosts get their act together soon and start using Passenger. There's no reason not to at this point- it is so much better for pretty much any setup. Using a whole VPS for a toy app is overkill.

Dreamhost has Passenger, but their UI is so lovely that you can't figure out how to do things half the time. Media Temple has the best UI I've used in my experience.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Route generation question time:
url_for, through polymorphic_url, can take an activerecord object (or group of them) and turn it into a route. Like url_for(Post.first) -> /post/1 by calling post_url which is a named route function generated by saying that Post is a resource. Or something. I don't use resources so I'm just guessing on that bit, but I do know the route generated would be something like map.post('/post/:id', :controller => 'post') and then some magic happens when Post.first is passed in :id gets matched with the route parameter.

Before I really dig into routing's code, what I want to know is if there's a way to use named routes, url_for and AR records in a way that works without needing the :id parameter. Like if I have...
code:
class Person < ActiveRecord::Base
   def first_name
      fullname.split(' ').first
   end
   def last_name
      fullname.split(' ').last
   end
end
and map.person('/person/:last_name/:first_name')
is there a way to do url_for(Person.first) -> /person/schmoe/joe without having to explicitly say url_for(person, :first_name => person.first_name, :last_name => person.last_name)?
It figures out that it needs to call person_url, but it doesn't dig into the model to see if last_name and first_name are able to be dropped into the route. Instead, it tries to positionally assign the arguments to url_for on top of the route parameters, so you end up with :last_name => #<User id: 1, fullname: "joe schmoe">, :first_name => nil.

Does what I'm asking make sense? Am I totally misunderstanding something?

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

Route generation question time:
url_for, through polymorphic_url, can take an activerecord object (or group of them) and turn it into a route. Like url_for(Post.first) -> /post/1 by calling post_url which is a named route function generated by saying that Post is a resource. Or something. I don't use resources so I'm just guessing on that bit, but I do know the route generated would be something like map.post('/post/:id', :controller => 'post') and then some magic happens when Post.first is passed in :id gets matched with the route parameter.

Before I really dig into routing's code, what I want to know is if there's a way to use named routes, url_for and AR records in a way that works without needing the :id parameter. Like if I have...
code:
class Person < ActiveRecord::Base
   def first_name
      fullname.split(' ').first
   end
   def last_name
      fullname.split(' ').last
   end
end
and map.person('/person/:last_name/:first_name')
is there a way to do url_for(Person.first) -> /person/schmoe/joe without having to explicitly say url_for(person, :first_name => person.first_name, :last_name => person.last_name)?
It figures out that it needs to call person_url, but it doesn't dig into the model to see if last_name and first_name are able to be dropped into the route. Instead, it tries to positionally assign the arguments to url_for on top of the route parameters, so you end up with :last_name => #<User id: 1, fullname: "joe schmoe">, :first_name => nil.

Does what I'm asking make sense? Am I totally misunderstanding something?

Use to_param

code:
class Person < ActiveRecord::Base
  def to_param
    fullname
  end
end
And make sure you modify your controller to find_by_fullname instead of find(_by_id).

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Oops, I should have mentioned I knew about to_param.

Given url_for(User.first) in a view:
I could use to_param to make it a little prettier: /person/:id as a route, giving me /person/joe-schmoe.

What I want is /person/:last_name/:first_name as a route, giving me person/schmoe/joe. Doing that requires url_for et al to look at the object I passed in beyond just taking the result from a to_param call.

I guess the polymorphic url helper wasn't really meant to be used like this, but it sort of surprised me it didn't do this :-\

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

Oops, I should have mentioned I knew about to_param.

Given url_for(User.first) in a view:
I could use to_param to make it a little prettier: /person/:id as a route, giving me /person/joe-schmoe.

What I want is /person/:last_name/:first_name as a route, giving me person/schmoe/joe. Doing that requires url_for et al to look at the object I passed in beyond just taking the result from a to_param call.

I guess the polymorphic url helper wasn't really meant to be used like this, but it sort of surprised me it didn't do this :-\

Any particular reason you want it to be person/schmoe/joe? Purely aesthetics? Going down this path seems like bad news to me.

skidooer
Aug 6, 2001

dustgun posted:

What I want is /person/:last_name/:first_name as a route, giving me person/schmoe/joe. Doing that requires url_for et al to look at the object I passed in beyond just taking the result from a to_param call.
You would have to make some pretty large changes to the current routing code to have it behave like you want. But you could always take a shortcut, like so:
code:
def url_for(options = {})
  if options.is_a?(Person) && !options.new_record?
    person_url(options.last_name, options.first_name)
  else
    super
  end
end

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

Praetorian42 posted:

Any particular reason you want it to be person/schmoe/joe? Purely aesthetics? Going down this path seems like bad news to me.
It was a somewhat contrived example that I didn't fully think through.

Here's the more practical one: I have a table full of CIDRs, represented by 2 integers - start_ip and end_ip. Having a route like /cidr/1 is dumb, as is /cidr/22605312/22605567 - I want cidr/1.88.238.0/24. It's easy enough to do as long as I use cidr_path(), but I really really want url_for to do this automagically because there are a bunch of cases where I get a list of objects back from something - say, search results - and they can be all different kinds of data. Country Names, Corporations, CIDR owners, Domain Names, etc. Right now the only way to iterate over those results and use the correct _path() method would be to do something like skidooer suggests.

I mean, that wouldn't be the worst thing in the world. It just feels like the current polymorphic routing is tantalizingly close to what I want :(

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

dustgun posted:

It was a somewhat contrived example that I didn't fully think through.

Here's the more practical one: I have a table full of CIDRs, represented by 2 integers - start_ip and end_ip. Having a route like /cidr/1 is dumb, as is /cidr/22605312/22605567 - I want cidr/1.88.238.0/24. It's easy enough to do as long as I use cidr_path(), but I really really want url_for to do this automagically because there are a bunch of cases where I get a list of objects back from something - say, search results - and they can be all different kinds of data. Country Names, Corporations, CIDR owners, Domain Names, etc. Right now the only way to iterate over those results and use the correct _path() method would be to do something like skidooer suggests.

I mean, that wouldn't be the worst thing in the world. It just feels like the current polymorphic routing is tantalizingly close to what I want :(

Why not just escape/sub the / before the mask? The only thing happening here (I think) is that the slash in a CIDR just happens to be the same character as a URI delimiter.

I see no problem with "/cidr/1.88.238.0|24" or something similar. Just gsub in the controller to get it to 'proper' format.

(I know this isn't what you're really looking for, but I'm a sucker for shortcuts.)

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

quote:

(I know this isn't what you're really looking for, but I'm a sucker for shortcuts.)
I usually am too - that's what's so weird about me obsessing over this!

I'll probably spend tonight figuring out how messy of a patch this would be, just for kicks.

NotShadowStar
Sep 20, 2000
The / in the URL isn't a problem, this is done all the time:

/2008/15/12

by doing:

map.connect ':year/:month/:day', :controller => 'blog', :action => 'by_date'

So you can do

/cidr/ip/mask as

map.connect 'cidr/:ip/:mask', :controller => 'cidr', :action => 'whatever'

Then if you want a helper method you'll have to add a to_url method in your cidr controller like skidooer mentioned. Unless I'm totally off on what you're trying to do

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
No, you aren't that far off, and right now I have a method in my application helper that hides of the messiness, but I still don't like it.

This was all sparked by me having url_for(@cidr) in a template and being surprised at getting :ip => #<Cidr id: 1, start_ip_address: 0, end_ip_address: 255> as part of the exception from cidr_url. It just seemed like I must have been doing something wrong, because it was getting the cidr_url call right, but then not matching up the route requirements with what attributes & methods @cidr had. Incidentally, it only took me a few minutes to come up with a dirty, 3 line patch that handles this and passes all existing rails tests.

Ok now go talk about something else!

phazer
May 14, 2003

chirp chirp i'm a buffalo
I'm using attachment_fu and rmagick to create an application for uploading PSDs and I'm unable to find, via google, a solution that converts the file into JPGs for making lightbox previews of the PSD. (I still want the PSD stored on the server, too, though.)

Thanks for any direction on this.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

phazer posted:

I'm using attachment_fu and rmagick to create an application for uploading PSDs and I'm unable to find, via google, a solution that converts the file into JPGs for making lightbox previews of the PSD. (I still want the PSD stored on the server, too, though.)

Thanks for any direction on this.

There's a tool that comes bundled with ImageMagick called 'convert'. Call from the command line "convert x.pdf x.jpg" and you're golden.

jonnii
Dec 29, 2002
god dances in the face of the jews

Praetorian42 posted:

There's a tool that comes bundled with ImageMagick called 'convert'. Call from the command line "convert x.pdf x.jpg" and you're golden.

He said psd, not pdf. If I remember correctly, ImageMagick can convert PSD files, but I'm not sure how up to date their support is. Worth a shot though.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

jonnii posted:

He said psd, not pdf. If I remember correctly, ImageMagick can convert PSD files, but I'm not sure how up to date their support is. Worth a shot though.

Oh poo poo you're right. convert should still work with PSDs, but it seems kind of sketch.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

phazer posted:

Can someone point me in the right direction for doing multiple file uploads in Rails2? I want to have 1 upload field with the ability to add more through AJAX. I'm googling but finding nothing valuable.

Here is a resource that does something like you want. It's not bad but I'd be wary; look at the updated code snippets on the page and read the comments because the video might be old.

http://railscasts.com/episodes/75-complex-forms-part-3

Flobbster posted:

Speaking of deployment...

I've been working on my first RoR application for the past month or so, and hope to deploy it in a couple weeks. (I haven't even approached it yet, I've been doing everything in development.)

In a couple of the RoR books I've been referring to, everything I've read makes deployment seem like so much unnecessary complexity (setting up an SVN repository, Capistrano...), and it has my eyes pretty much glazing over, though partly I'm sure because I'm not ready for it yet.

As I go back to RTFM some more, I'm hoping someone can just give it to me straight -- is it possible to deploy a site simply by uploading my app's directory tree (and the SVN stuff is just for things like managing updates/changes more easily), or do I really need to deal with all this extra cruft for even the most basic site?

With regard to SVN and github and Capistrano and all that crap, you don't really need to use Capistrano to deploy your application. Find a good host that supports Rails and check out their FAQ section, most of them will walk you though getting your application running through FTP (or SFTP if you prefer) and a terminal window.

My favorite program on os x for doing this is Coda, I don't know if I'd use it for development but it makes it easy to work on files that are server side. It's pricey but there is a demo available that will get you running. On Windows I recommend WinSCP, WinSCP rocks.

Honestly if you try and jump right into Capistrano with your pants off you're going to get decapitated, I know a lot about how Capistrano works and have had to use it a huge number of times after getting 1 on 1 training. I think it is absurd, overly complicated, useless for something as simple as most Rails apps are.

Here is my favorite host's deployment FAQ.

http://wiki.railsplayground.com/railsplayground/show/Troubleshoot+Common+Rails+Deployment+and+Setup+issues

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Nolgthorn posted:

Honestly if you try and jump right into Capistrano with your pants off you're going to get decapitated, I know a lot about how Capistrano works and have had to use it a huge number of times after getting 1 on 1 training. I think it is absurd, overly complicated, useless for something as simple as most Rails apps are.

Here is my favorite host's deployment FAQ.

http://wiki.railsplayground.com/railsplayground/show/Troubleshoot+Common+Rails+Deployment+and+Setup+issues

Thanks for this. I've been reading a little more ("Deploying Rails Applications" from Pragmatic Bookshelf) and if I'm understanding everything it looks like Capistrano does everything over SSH, which means it's out for me -- the host I'm using charges extra for SSH each month, an option that I declined (the site I'm designing is just a simple art site for my dad, so there's no reason for him to pay for something he'll never use, and once the site is deployed I won't need to touch it very often either), so that's why I've been so concerned with a simple "upload and go" method of deployment.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Flobbster posted:

Thanks for this. I've been reading a little more ("Deploying Rails Applications" from Pragmatic Bookshelf) and if I'm understanding everything it looks like Capistrano does everything over SSH, which means it's out for me -- the host I'm using charges extra for SSH each month, an option that I declined (the site I'm designing is just a simple art site for my dad, so there's no reason for him to pay for something he'll never use, and once the site is deployed I won't need to touch it very often either), so that's why I've been so concerned with a simple "upload and go" method of deployment.

I don't think it is possible to restart the mongrel service your app is running on without SSH and I don't think it is possible to run rake tasks without it. If you run the rake tasks locally, then export and insert the database changes onto the host's phpmyadmin you might be alright. You'd need to contact their support every time that you need to restart the mongrel service.

If I were you I'd pay for SSH or get a better host, charging you to use SSH is a sort of manufactured fake service fee.

A few quick tips for deployment without capistrano.

1) Freeze the plugins, gems and rails to your vendor folder before uploading.
2) To reduce the chance of corrupted files, either gzip your project before uploading it and ungzip on the server or use SFTP/SSH protocol to transfer it.
3) Upload your application somewhere on the server outside of ~/public_html.
4) Set the permissions recursively on the entire application that you uploaded to 755.
5) Some hosts don't like this on writable directories, so you may have to change your log directory and any file storage directories to 777.
6) Manually update the ~/app/public/.htaccess file to reflect the server and the fact you want to use dispatch .fcgi not .cgi as the file being referenced.
7) Check to ensure ~/app/public/dispatch.fcgi has the correct #!bash line.
8) Create the database on the server, update the production config.yml to use the new db settings.
9) Populate the database with rake.
10) Manually update environment.rb to remove the comment before the environment = production thingy.
11) Delete ~/public_html then create a symlink to the ~/app/public directory in its place.
12) Restart mongrel.

If you are developing on a Windows machine then there are a lot more steps that would need to be added to the above list, all other operating systems (*nix/osx) you will be fine.

Alternatively you can go through the motions to use capistrano, but you'll find the above steps to be much faster. No matter what OS you are using capistrano just takes all the stuff you would have to do, adds a lot more convolution to it, then forces you to start over again when you don't configure it not to break itself every time.

Someone probably has had a different experience with Capistrano that I have, but regardless it is bloated and absurd. I was thinking all we really need is a simple bash script that does all this stuff anyone up for it?

jonnii
Dec 29, 2002
god dances in the face of the jews

Nolgthorn posted:

Someone probably has had a different experience with Capistrano that I have, but regardless it is bloated and absurd. I was thinking all we really need is a simple bash script that does all this stuff anyone up for it?

There are alternatives to Capistrano: http://rubyhitsquad.com/Vlad_the_Deployer.html

Personally I use Capistrano, and haven't had any problems with it. My deploy.rb file is 35 lines and could probably be made even smaller.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Nolgthorn posted:

I don't think it is possible to restart the mongrel service your app is running on without SSH and I don't think it is possible to run rake tasks without it. If you run the rake tasks locally, then export and insert the database changes onto the host's phpmyadmin you might be alright. You'd need to contact their support every time that you need to restart the mongrel service.

When I go to the Rails section of my cPanel, there are controls that let me start/stop each application that I have on there. I assume this is what you're referring to?

The database stuff is pretty minor (only one model right now), so doing that by hand isn't much trouble either. Once the site is up it's going to remain more-or-less static, and any changes I have to make are more likely to be HTML/CSS stuff rather than to the model.

As for getting a new host, maybe at some point down the road -- for now though, it's a goon-host that I've had great experiences with in the past, and since web development ain't my main forte, I went with what I knew. The lack of SSH didn't seem to be a big deal for this project, especially when all my dad cares about is "$20 a year? That sounds good."

Thanks for all the other tips too! I'm gonna be deploying this within the next week or two hopefully, so I'm keeping my fingers crossed.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I would pay $5 a month and do, it is not a huge sum of money and you get what you pay for. :)

If they provide you with a utility to restart mongrel services with the click of a mouse it is still a hack but at least they give you something.

phazer
May 14, 2003

chirp chirp i'm a buffalo

Praetorian42 posted:

There's a tool that comes bundled with ImageMagick called 'convert'. Call from the command line "convert x.pdf x.jpg" and you're golden.

So can I make my application call that command?

skidooer
Aug 6, 2001

phazer posted:

So can I make my application call that command?
code:
%x{convert x.psd x.jpg}
exec('convert', 'x.psd', 'x.jpg')
system('convert x.psd x.jpg')
`convert x.psd x.jpg`
To name a few.

skidooer fucked around with this message at 19:25 on Dec 17, 2008

NotShadowStar
Sep 20, 2000
There is also RMagick, which enables you to call ImageMagick APIs in Ruby. ImageMagick has usually been lovely to install in my experience though, doubly so on OSX.

http://www.imagemagick.org/RMagick/doc/comtasks.html#convert

phazer
May 14, 2003

chirp chirp i'm a buffalo

NotShadowStar posted:

There is also RMagick, which enables you to call ImageMagick APIs in Ruby. ImageMagick has usually been lovely to install in my experience though, doubly so on OSX.

http://www.imagemagick.org/RMagick/doc/comtasks.html#convert

Yea I'm using Rmagick with the attachment_fu plugin. Thanks!

phazer
May 14, 2003

chirp chirp i'm a buffalo
edit: I've decided to go another route on this problem. Thanks!

phazer fucked around with this message at 20:01 on Dec 18, 2008

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Trouble with custom REST actions

I have a model called "artwork", which represents a piece of art in a gallery. It's got all the usual RESTful stuff -- an artworks_controller with the standard 7 actions, their corresponding ERb templates, etc etc.

The artworks_controller uses :before_filter :login_required because only the site admin should be able to view the list of artworks, create new ones, and modify them. The actual gallery front page is done in my main_controller.

Now, I want to add a custom action called display to artworks_controller that will basically just display a single artwork, along with some metadata, which I can link to in the gallery, and this action will be publicly accessible. So first, I do this:
code:
  before_filter :login_required, :except => :display
Then, based on this Railscast, I added the following method to artworks_controller:
code:
  def display
    @artwork = Artwork.find(params[:id])
    
    respond_to do |format|
      format.html # display.html.erb
    end
  end
...and the following to my routes.rb:
code:
  map.resources :artworks, :member => { :display => :get }
I also created the appropriate display.html.erb template in /app/views/artworks:
code:
<!-- other stuff -->
<%= image_tag @artwork.master_image_path,
    :width => @artwork.master_size[:width], :height => @artwork.master_size[:height] %>
<!-- other stuff -->
In my main gallery, I have a link like this:
code:
<%= link_to "Enlarge", display_artwork_path(artwork), :target => "_blank" -%>
where artwork is the current artwork in a loop that generates the gallery. I know at this point that it's valid because I use other properties of it to display the image and title.

The problem is, when I click on that link, the correct template (display.html.erb) gets loaded, but inside it @artwork is nil, so I get an error when it tries to render. Furthermore, when I try to do any logging at the top of the display method, I don't see the output anywhere, so I'm not entirely sure the method is getting called properly, and that's why @artwork would be coming back unset.

Any ideas? I'm still learning some Rails basics here, so if there's anything I'm doing that isn't best practices, please jump down my throat so I can fix them.

NotShadowStar
Sep 20, 2000
map.resources is a shorthand that creates routes for the methods destroy, update, edit, show, create, new, index. You have the method 'display' which isn't explicitly mapped yet.

So when you do app/display/1 the 1 isn't caught as :id, you have to create a new route to do that. I think instead of :members you're looking for :collection but I've never actually added routes in that manner and the documentation is sparse.

Although what's concerning to me is why you need a separate 'display' method when 'show' is supposed to do exactly what you're doing (show a single record).

That's my theory, you can see if I'm off by doing in the controller (temporarily to figure out WTF)

raise ApplicationError, 'No id!' unless params[:id]
@artwork = Artwork.find params[:id]

NotShadowStar fucked around with this message at 00:00 on Dec 20, 2008

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

NotShadowStar posted:

map.resources is a shorthand that creates routes for the methods destroy, update, edit, show, create, new, index. You have the method 'display' which isn't explicitly mapped yet.

So when you do app/display/1 the 1 isn't caught as :id, you have to create a new route to do that. I think instead of :members you're looking for :collection but I've never actually added routes in that manner and the documentation is sparse.

My (possibly incorrect) understanding from the Railscast that I linked was that :collection routes were meant to operate on the entire collection of records (so they wouldn't take an id as a parameter), while :member routes operate on a single specific record.

His example uses a :collection route to create a page that shows a list of completed tasks (vs. all task records) and a :member route that marks a single record as complete. My use case is pretty similar to the latter, which is why I'm not sure what the difference is here that's causing it not to work.

quote:

Although what's concerning to me is why you need a separate 'display' method when 'show' is supposed to do exactly what you're doing (show a single record).

I'm keeping the 'show' action separate and protected behind the authentication :before_filter because it's intended to be used in the admin section of the site (along with the other actions) to show additional private information, with a different layout. 'display' is essentially a simplified version with a different layout, intended for public viewing.

Given that, maybe artworks_controller isn't the best place to put this action? Maybe since it's intended to be invoked from my main_controller, I should just write it as an action in main_controller instead? I put it in artworks_controller because that seemed like the RESTful way to do it.

quote:

That's my theory, you can see if I'm off by doing in the controller (temporarily to figure out WTF)

raise ApplicationError, 'No id!' unless params[:id]
@artwork = Artwork.find params[:id]

I put that in my 'display' method and nothing changes -- so I took out the unless clause to make it raise no matter what, and still nothing :raise: So it definitely looks like it's not being called at all, and Rails is just happily trying to render the template anyway, which explains why my instance variable is nil at least.

NotShadowStar
Sep 20, 2000
Whoops, there's no such class as ApplicationError but it should still crash and burn just the same. You could just raise Exception. SInce it's not anyway, that's making me wonder what's going on. What's the URL you're using/generating? It should look like app/artwork/display/1. Also what does rake routes say? FURTHERMORE,..;!! if you change your routes I find it's best to restart the server, it seems to act funky even in devel mode I've found.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Flobbster posted:

I'm keeping the 'show' action separate and protected behind the authentication :before_filter because it's intended to be used in the admin section of the site (along with the other actions) to show additional private information, with a different layout. 'display' is essentially a simplified version with a different layout, intended for public viewing.

Dude, that's what if statements are for. Seriously.

code:
def show
  @artwork = Artwork.find(params[:id]
  if logged_in?
    render :action => "show"
  else
    render :action => "display"
  end
end
Off-topic, but bugs me: Don't bother with that respond_to crap unless you have more than one format that you're responding to. In the meantime it is just adding in noise.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

NotShadowStar posted:

Whoops, there's no such class as ApplicationError but it should still crash and burn just the same. You could just raise Exception. SInce it's not anyway, that's making me wonder what's going on. What's the URL you're using/generating? It should look like app/artwork/display/1. Also what does rake routes say? FURTHERMORE,..;!! if you change your routes I find it's best to restart the server, it seems to act funky even in devel mode I've found.

The URLs generated by "display_artwork_path" are like "/artworks/2/display". This is consistent with the standard actions that do work. Here's the relevant output from rake routes:
code:
                 display_artwork GET    /artworks/:id/display                {:controller=>"artworks", :action=>"display"}
       formatted_display_artwork GET    /artworks/:id/display.:format        {:controller=>"artworks", :action=>"display"}

Praetorian42 posted:

Dude, that's what if statements are for. Seriously.

:aaa: But seriously, the "display" and "show" actions serve different purposes. Without spending paragraphs explaining the site design, basically the "display" action is used for showing an enlarged version of the art from the main gallery; the "show" action is for displaying it, along with private data, in the admin section of the site. Even if an admin user is logged in, when they click on the link from the main gallery, I want "display" to do what it would normally do, which is distinct from "show", hence the need for a separate action.

I'll rename it "enlarge", so we stop getting hung up on the synonym and overlooking the actually problem here, which is why an action method isn't getting called.

quote:

Off-topic, but bugs me: Don't bother with that respond_to crap unless you have more than one format that you're responding to. In the meantime it is just adding in noise.

Good to know -- I just copied and pasted the action from another one and removed the XML entry that the scaffolding had put in there. There's quite a big of magic here to get used to, that's for sure.

Adbot
ADBOT LOVES YOU

wunderbread384
Jun 24, 2004
America's favorite bread
That route looks like it should work, what do the logs say when you make the request? It should have the name of the action and controller that was called in there, plus the parameters.

Edit: Also, is the method private maybe? I would imagine Rails should throw an error if that happens but many things in Rails don't happen the way I imagine.

wunderbread384 fucked around with this message at 01:30 on Dec 20, 2008

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