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
Evil Trout
Nov 16, 2004

The evilest trout of them all
Here's a script I created to add all new files to the repo. It's good for non-generated content like javascripts and stylesheets:

#!/bin/sh

svn add `svn status | grep "^\?.*" | sed "s/^\? *//"`

Adbot
ADBOT LOVES YOU

hmm yes
Dec 2, 2000
College Slice
If you're working in textmate, you also have a bundle that lets you do most subversion commands easily. It's called by hitting ctrl+shift+a from inside a file window or by selecting a file or folder from the drawer. This makes it easy to add a new file then add it to subversion: fruit+shift+n => type name => ctrl+shift+a => 1.

HIERARCHY OF WEEDZ
Aug 1, 2005

I am extremely slowly picking my way through deployment with Capistrano, and I've already hit a snag. The (really shittily sparse) manual tells you to create a Capfile for a project with `capify ~/project`. What I don't understand is, this creates a config/deploy.rb file in your project. But - Capistrano is supposed to be getting the latest project from Subversion. How come the deploy.rb is linked to a checkout of the pristine code?

I'm sorry if I'm being difficult to understand - it just seems like there's a disconnect there. If you have a deployment system that's looking to checkout your code from source control and place it on a server, how come it's not completely removed from the code?

Yossarian22
Dec 10, 2004
Minister

shopvac4christ posted:

I am extremely slowly picking my way through deployment with Capistrano, and I've already hit a snag. The (really shittily sparse) manual tells you to create a Capfile for a project with `capify ~/project`. What I don't understand is, this creates a config/deploy.rb file in your project. But - Capistrano is supposed to be getting the latest project from Subversion. How come the deploy.rb is linked to a checkout of the pristine code?

I'm sorry if I'm being difficult to understand - it just seems like there's a disconnect there. If you have a deployment system that's looking to checkout your code from source control and place it on a server, how come it's not completely removed from the code?
You theoretically dont need to commit your deploy.rb file to your repo to get it to work. Cap deploy reads off your local copy so whatever is in your local deploy.rb file is what gets executed.

HIERARCHY OF WEEDZ
Aug 1, 2005

Yossarian22 posted:

You theoretically dont need to commit your deploy.rb file to your repo to get it to work. Cap deploy reads off your local copy so whatever is in your local deploy.rb file is what gets executed.

Right. But what I'm asking is why is there a deploy.rb file at all? Why aren't the deployment instructions completely independent of whether or not there's a copy of the source code checked out?

Evil Trout
Nov 16, 2004

The evilest trout of them all

shopvac4christ posted:

Right. But what I'm asking is why is there a deploy.rb file at all? Why aren't the deployment instructions completely independent of whether or not there's a copy of the source code checked out?

The way Capistrano works is that it tunnels through SSH and executes a series of instructions on a remote machine. It needs to be run FROM somewhere, usually on a development machine that has a copy of the source locally.

If it were a server process you could just notify it to deploy itself, sure.

The deploy.rb is part of the instructions you're running that in turn execute remote SSH commands.

HIERARCHY OF WEEDZ
Aug 1, 2005

Grob posted:

The way Capistrano works is that it tunnels through SSH and executes a series of instructions on a remote machine. It needs to be run FROM somewhere, usually on a development machine that has a copy of the source locally.

If it were a server process you could just notify it to deploy itself, sure.

The deploy.rb is part of the instructions you're running that in turn execute remote SSH commands.

What I'm trying to say is, why can't we have something along the lines of a deployments directory, that has deploy.rb's and subdirectories for all the applications we can deploy, which is completely unrelated to any local checked out copies of the source?

For example,
code:
# ls ~/Deployments
MyApp1 MyApp2 MyApp3
# ls ~/Deployments/MyApp1
deploy.rb
Since the SVN information is in the deploy.rb, there's no need to even have a checked out copy of the application available to deploy it. It doesn't even have to be on a server or anything - just a machine that has deployment recipes that may or may not also be used for development.

hmm yes
Dec 2, 2000
College Slice
I think the reasoning is that it allows all project files to fall under one folder. Your method spreads them out--whether that is better or not is probably up to individual opinions. I like having everything in one place. Anyone who checks out the project can make changes, commit to the repo, and deploy to the webserver all from one place.

You could achieve what you want with some rake tasks, though.

skidooer
Aug 6, 2001

shopvac4christ posted:

What I'm trying to say is, why can't we have something along the lines of a deployments directory, that has deploy.rb's and subdirectories for all the applications we can deploy, which is completely unrelated to any local checked out copies of the source?
There's no reason why you couldn't do that. But considering that you're most likely going to want to keep the deploy file in version control, and you're going to want to check out the latest version of the source to run your test suite before deployment, keeping it as part of the application seems much more convenient to me.

drjrock_obgyn
Oct 11, 2003

once i started putting pebbles in her vagina, there was no going back

shopvac4christ posted:

What I'm trying to say is, why can't we have something along the lines of a deployments directory, that has deploy.rb's and subdirectories for all the applications we can deploy, which is completely unrelated to any local checked out copies of the source?

For example,
code:
# ls ~/Deployments
MyApp1 MyApp2 MyApp3
# ls ~/Deployments/MyApp1
deploy.rb
Since the SVN information is in the deploy.rb, there's no need to even have a checked out copy of the application available to deploy it. It doesn't even have to be on a server or anything - just a machine that has deployment recipes that may or may not also be used for development.

This is true and you don't technically need to follow the way capistrano does things. It would really help if you did, though, because cap is opinionated (but configurable) software.

Given your example, I'm not sure I see the benefit in having ~/Deployments/MyApp1/deploy.rb vs ~/Apps/MyApp1/config/deploy.rb. You've traded having a deployments directory for having a directory with access to the source code. Also, you may want to have custom recipes which may be easier to remember why the functions do what they do if they're right there in the app.

Also, since is the RoR love in thread, I just started a RoR news podcast. Shameless self promotion at http://www.railsenvy.com/podcast.

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

vg8000
Feb 6, 2003

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

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?

I tend to do the same thing.

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.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
I'm very suddenly having a very odd problem. I'm running instant rails on vista, and as of last night, I can't start up mySql because
code:
---------------------------
MySQL
---------------------------
Either Apache or MySQL cannot run because another program is using it's port.
---------------------------
OK   
---------------------------
how do I figure out what port is being blocked, what's blocking it, and how to change that in mySQl or the other program?

vg8000
Feb 6, 2003

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

MrSaturn posted:

I'm very suddenly having a very odd problem. I'm running instant rails on vista, and as of last night, I can't start up mySql because
code:
---------------------------
MySQL
---------------------------
Either Apache or MySQL cannot run because another program is using it's port.
---------------------------
OK   
---------------------------
how do I figure out what port is being blocked, what's blocking it, and how to change that in mySQl or the other program?

Mysql's port is 3306, Apache's is 80 (unless you changed the ports they listen on). You might have another web server running on port 80 or something, check that first.

Hammertime
May 21, 2003
stop

vg8000 posted:

Mysql's port is 3306, Apache's is 80 (unless you changed the ports they listen on). You might have another web server running on port 80 or something, check that first.

i.e. make sure IIS isn't stealing 80.

MrSaturn
Sep 8, 2004

Go ahead, laugh. They all laugh at first...
IIS is definitely off. I just checked.

hmm yes
Dec 2, 2000
College Slice
Bumping this so that it can get some Caverns of Cobol loving

markerstore
Dec 5, 2003
Canny!
I'm trying to write a test for a controller which handles AJAX requests and renders a partial in response. However, the locals I pass to the partial don't seem to be available to the test via the "assigns" hash. Is there any way to get at those?

Argue
Sep 29, 2005

I represent the Philippines
I have a feature which lets a user make a mailing list, then send a notice to everyone telling them to take an online student survey. The mailing list consists only of email addresses, so what I figured on doing is assigning a unique (and unguessable) string to each invitation, so that I can tell which email address responded.

What's the best way to approach the string generation with Rails (using MySQL)? I'm assuming that I'll either be making some sort of sequence on the database, or I'll be keeping a counter, then salting and hashing it. Alternatively, is there a better way of tracking which students have responded short of requiring their own login?

Pardot
Jul 25, 2001




How about some sort of digest (md5 or sha2 or whatever) of their email address and some random salt you store with the address?

Argue
Sep 29, 2005

I represent the Philippines

Anal Wink posted:

How about some sort of digest (md5 or sha2 or whatever) of their email address and some random salt you store with the address?

That'll work too; I'll probably be using that until I find a better solution. Ultimately, though, I'm worried about collisions, so I'm trying to find a more elegant solution.

I've found a module for Rails called usesguid, but it seems to only work on the primary key column, and based on the sample GUIDs, I think one could guess a GUID by incrementing a number or two.

floWenoL
Oct 23, 2002

Argue posted:

Ultimately, though, I'm worried about collisions, so I'm trying to find a more elegant solution.

For md5/sha1 assuming no malicious input? :psyduck:

HIERARCHY OF WEEDZ
Aug 1, 2005

I have a rake task that is supposed to download and extract a '.zip' file. I'm running system commands, so something like
code:
`unzip -f -d #{extract_dir} #{zip_file}`
It's not portable, but I switched from zipfilesystem because every time I attempted to do the extraction with zipfilesystem, I would get an error about a corrupt archive. But now this code won't work either - the unzip command, both on my dev machine and the live server, says the archive is corrupt, which is bullshit because I can cancel the rake task and run the command it runs, and everything works perfectly.

Someone I spoke to suggested a permissions error, but I doubt I would get this message if it were a permissions error:

quote:

End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /blah/blah/blah/archive.zip or ...

Of course, that last line is also bullshit, since that's exactly where the archive is.

Argue
Sep 29, 2005

I represent the Philippines

floWenoL posted:

For md5/sha1 assuming no malicious input? :psyduck:

I guess I'm being paranoid, but if the two of you are saying it's an acceptable solution, then I'll gladly stick with that; it's much easier to implement after all.

Trabisnikof
Dec 24, 2005

Argue posted:

I guess I'm being paranoid, but if the two of you are saying it's an acceptable solution, then I'll gladly stick with that; it's much easier to implement after all.

That's what I use for a similar requirement.
code:
def hash_email
    d = Digest::SHA1
    salt = "salt salt salt?"
    d.hexdigest( self.email + salt)
  end
Shouldn't have to really worry about collisions and since I'm not using MD5 it will be unlikely someone will rainbow table it.

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!

shopvac4christ posted:

I have a rake task that is supposed to download and extract a '.zip' file. I'm running system commands, so something like
code:
`unzip -f -d #{extract_dir} #{zip_file}`
It's not portable, but I switched from zipfilesystem because every time I attempted to do the extraction with zipfilesystem, I would get an error about a corrupt archive. But now this code won't work either - the unzip command, both on my dev machine and the live server, says the archive is corrupt, which is bullshit because I can cancel the rake task and run the command it runs, and everything works perfectly.

Someone I spoke to suggested a permissions error, but I doubt I would get this message if it were a permissions error:


Of course, that last line is also bullshit, since that's exactly where the archive is.

Sounds more like you've got a space in your path name (or some other character that needs escaping). Wrap your paths in single-quotes.

Pardot
Jul 25, 2001




Trabisnikof posted:

That's what I use for a similar requirement.
code:
def hash_email
    d = Digest::SHA1
    salt = "salt salt salt?"
    d.hexdigest( self.email + salt)
  end
Shouldn't have to really worry about collisions and since I'm not using MD5 it will be unlikely someone will rainbow table it.

If you're worried even in the slightest, just store a new random salt for each email address. That would prevent any sort of rainbow tables and isn't hard to do at all.

Trabisnikof
Dec 24, 2005

Anal Wink posted:

If you're worried even in the slightest, just store a new random salt for each email address. That would prevent any sort of rainbow tables and isn't hard to do at all.

Actually, that is a good idea. Although, isn't that still weak to Rainbow Tables, just each hash requires a new lookup? I may not have my concept of Rainbow Tables right though.

Pardot
Jul 25, 2001




Trabisnikof posted:

Actually, that is a good idea. Although, isn't that still weak to Rainbow Tables, just each hash requires a new lookup? I may not have my concept of Rainbow Tables right though.

No, they would have to make a new rainbow table for each salt, which makes the whole reason to make a rainbow table worthless.

Hop Pocket
Sep 23, 2003

I've been using my free time to code some RoR apps, and it's going fairly well. I have a dreamhost account that uses FastCGI to run the rails apps. When I deploy using Capistrano, there's a 10-15 second delay which is I'm assuming the FastCGI processes restarting because of the application change. However, if I check the deployed site after an hour or two of inactivity, I get the same delay.

In both cases, the site runs snappy after the first hit to the webapp. Is there a way to force the FastCGI processes to stay running (assuming that this is the cause of the delay)?

freeb0rn
Jan 22, 2005

Hop Pocket posted:

I've been using my free time to code some RoR apps, and it's going fairly well. I have a dreamhost account that uses FastCGI to run the rails apps. When I deploy using Capistrano, there's a 10-15 second delay which is I'm assuming the FastCGI processes restarting because of the application change. However, if I check the deployed site after an hour or two of inactivity, I get the same delay.

In both cases, the site runs snappy after the first hit to the webapp. Is there a way to force the FastCGI processes to stay running (assuming that this is the cause of the delay)?

That is the cause of the delay and the solution is a script that loads the site every X minutes.

From the Dreamhost wiki:
http://wiki.dreamhost.com/Ruby_on_Rails#Switching_to_FCGI_with_Dreamhost
See the section "Preventing timeouts using curl and cron"

freeb0rn fucked around with this message at 20:41 on Nov 10, 2007

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It seems Active Record will not save grandchildren and their parent at the same time, am I doing something wrong or is it something to do with my polymorphic association?

code:
#Section has_one SideColumn
#SideColumn has_one ColumnImage as "attachment" (polymorphic)

    @side_column = SideColumn.new(params[:side_column])
    return unless request.post?
    @section.side_column = @side_column
    unless params[:column_image].empty?
      @section.side_column.column_image = ColumnImage.new(params[:column_image])
    end
    @section.save

#=> SideColumn gets saved but ColumnImage does not.
I have verified params[:column_image] is not empty, when I comment out the conditional I still get the same result.


It's not really relevant but here is a pastie of my models if someone needs to see.
http://pastie.caboo.se/116397

hmm yes
Dec 2, 2000
College Slice
Just throwing an idea out there, but have you tried manually adding save?

code:
unless params[:column_image].empty?
   @section.side_column.column_image = ColumnImage.new(params[:column_image])
   @section.side_column.column_image.save
end

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
In this example SideColumn would not have been created yet so it would undoubtedly throw an error since ColumnImage would not have a row in the database to reference.

I would have to save ColumnImage separately afterwards, but I'm trying to get it all into one nice neat transaction.

copla
Jun 12, 2005
Everything will fall, fall right into place
I'm trying to style my XML with XSL and then spit it out as html using REXML and Ruby-XSLT... problem being, I can't seem to open up my files.

This is my model:
code:
  def self.find_blog_posts

    require "net/http"
    require "net/https"
    require "rubygems"
    require "rexml/document"
    require "xml/xslt"
    include REXML
    
    doc = XML::XSLT.new()
    doc.xml = REXML::Document.new File.new("/blog.xml")
    doc.xsl = REXML::Document.new File.new("/blox.xsl")
    @slider_content = xslt.serve() 
  end    
The error I get is:

code:
>> Home.find_blog_posts
Errno::ENOENT: No such file or directory - /blog.xml
	from /Users/copla/project/app/models/home.rb:52:in `initialize'
	from /Users/copla/project/app/models/home.rb:52:in `new'
	from /Users/copla/project/app/models/home.rb:52:in `find_blog_posts'
	from (irb):1
I haven't had any issue opening and calling files from my stylesheets and my view files, from view I just do "/images/file.jpg" to call an image in public/images, but I can't do the same from model- when I do "/blog.xml" for it being in public/blog.xml, it doesn't work. When I do "/stylesheets/blog.xml", it doesn't work (for that I try moving the file to stylesheets of course, it's currently moved back to public). It also opens properly when I open it directly in my browser, so it's clear that I'm using the wrong syntax.

How exactly are you supposed to open a file in public from model?

Argue
Sep 29, 2005

I represent the Philippines

copla posted:

How exactly are you supposed to open a file in public from model?

You don't want to do that. Not in the model, at least. The entire point of splitting your code into model, view, and controller is to keep your logic separate from your presentation. The public folder is for the web layer, so if you open files from public in your model, that means that when you modify the presentation layer, you'll have to worry about not accidentally screwing up the internals of the application.

copla
Jun 12, 2005
Everything will fall, fall right into place

Argue posted:

You don't want to do that. Not in the model, at least. The entire point of splitting your code into model, view, and controller is to keep your logic separate from your presentation. The public folder is for the web layer, so if you open files from public in your model, that means that when you modify the presentation layer, you'll have to worry about not accidentally screwing up the internals of the application.
I guess I should have explained the purpose of the XML files first- right now I'm trying to test that Ruby-XSLT will transform the XML right when I have a file locally, because I was having a hell of a time pulling down a remote XML file. What I want to do, ideally, is pull down the XML from the server (I'm getting blog posts from the Tumblr API, which you get with an HTTP request, and then get back the XML. I then need format it with the XSLT- so what I'm trying to do now is just get local XML working and formatting right.

Then I can work on pulling down the XML and somehow saving it, as it comes in as pure text, so it would need to have a declaration added at the beginning, then I can transform that, in turn, with the XSL. And THEN I can hopefully get it so that all of it happens serverside, updated hourly, and cached.

But... now I need to open up the local file so I can test the first step.

wunderbread384
Jun 24, 2004
America's favorite bread
If you're just testing why not use the absolute path? Or an environmental variable if for some reason you want to deploy it to stage or production.

Adbot
ADBOT LOVES YOU

Al Azif
Nov 1, 2006

copla posted:

This is my model:
code:
...
    doc.xml = REXML::Document.new File.new("/blog.xml")
    doc.xsl = REXML::Document.new File.new("/blox.xsl")
...

/blog.xml is an HTTP path, you want a path to that file on your hard drive.

quote:

I haven't had any issue opening and calling files from my stylesheets and my view files, from view I just do "/images/file.jpg" to call an image in public/images, but I can't do the same from model- when I do "/blog.xml" for it being in public/blog.xml, it doesn't work.

You know how HTML and CSS work, right? When code in a view refers to /images/something.jpeg it's not actually opening that file, it just makes a reference to it in the HTML it generates, and the user's browser requests the file.

Once you've figured out the correct path to use ("public/blog.xml" should probably work), you should just pass that straight to ruby-xslt, eg:

code:
doc.xml = "/blog.xml"
It will read and parse the file itself. There's no point in parsing it with REXML beforehand, ruby-xslt just turns it back into a string and parses that.

To process a remote file:

code:
require "open-uri"
doc.xml = open("http://example.org/some-file.xml").read

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