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
dustgun
Jun 20, 2004

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

cYp posted:

I'm either going to get started learning PHP or Ruby on rails. I'm currently leaning towards php. Will this be a mistake in the future?
Learn Ruby, then Ruby on Rails.

Adbot
ADBOT LOVES YOU

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
What hosts are you internet dudes using for your rails stuff?

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
It's just all so expensive for something that I'm not sure will last :(

Hop Pocket posted:

I'm using Joyent. I don't have a good frame of reference, as I'm fairly new to Rails and that particular world, but I will say that I have found their support to be really helpful and responsive.
How flexible are they with upgrading bandwidth once you're a customer? I'm pushing around 10GB a day right now, going up around 1.5GB a week (nearly all of which are images I could probably keep on dreamhost, or toss on S3 or something I guess). I also do image processing in 1080p a dozen or so times a day, so, I'm sort of wondering how their CPU bursting stuff works. Do you get charged for it? Is this is just something I should email about?

Railsmachine looks to be way out of my price range right now, at any rate.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Looks like I'll probably sign up for a year of the base Accelerator package on Wednesday, unless something better comes around -- $45 for what they offer isn't bad or anything, I just wish it had more bandwidth.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Like ikari said, it's more of an "in theory" thing. No one in their right mind fucks around with the low level stuff, and if someone did in a widely distributed library, there would be a hell of an uproar about how stupid they are. In practice, open classes are fantastic and make so many things so simple.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
With dreamhost and fastcgi, you learn about rails optimizations really fast. I recommend everyone do it once.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
What's the migration that you're using?

dustgun fucked around with this message at 05:07 on May 1, 2008

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
This is more of a general ruby question, but how the hell do I unpack a utf8 string in ruby 1.8 and get it so that \xC2\xAE actually shows up as ® in the output? I've never really done this stuff, and feel sort of lost googling around.

dustgun
Jun 20, 2004

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

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Perfect, thanks.

dustgun
Jun 20, 2004

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

Pardot posted:

I could be wrong, but I don't think you can do that with something like shoes. I think the best you can do is do something in jruby and package that into bytecode. I haven't looked into any of this myself, but I think there is at least one jruby UI thing. This is all just vague recollections from my rss feeds, though.

quote:

Okay, the latest set:

* http://code.whytheluckystiff.net/dist/shoes-0.r724.exe
(windows + video support; 7.3M)
* http://code.whytheluckystiff.net/dist/shoes-0.r724-intel.dmg
(osx-intel + video support; 7.9M)
* http://code.whytheluckystiff.net/dist/shoes-0.r724.tar.gz
(source; 550K)

This build includes support for packaging Shoes apps as EXEs and
DMGs. This'll be covered in a hackety.org blog post in a few
minutes.

For smaller non-video builds, see the Recent Builds page:
http://code.whytheluckystiff.net/shoes/wiki/RecentBuilds

_why
Just came a few minutes ago :)

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Is there a way to explicitly set the id, instead of letting it auto_increment, when creating a record with AR? I'd prefer not to do this in actual SQL, but whatever if I have to I have to.

dustgun
Jun 20, 2004

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

Mr. Wynand posted:

I don't know of hand, but are you absolutely sure you have to?
I don't, but it's something I want to do to keep things cleaner in the future. Basically, I'm normalizing a table ("files") a bit so that I can trim down that table, and then join the specific type ("images", "movies", etc..) with it to get the general details. So like now you can do /movies/:id or /images/:id and it just looks up the info in 'files', but I want to have it do the lookup in 'movies' or 'images' against the id, not file_id. That way 'movies' and 'images' will increment independently of one another from now on, but existing ids will remain the same.

Crap, that's a horrible explaination. Eitherway, it's something I started doing and then sort of wondered if you could do it with AR :)

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Hopefully this sort of maybe helps.

code:
x = [[4.0, 231], [1.5, 423], [4.0, 2312], [5.0, 231], [3.5, 423], [4.0, 342]]
x = x.map{ |sub| 
  same = x.select{|c|c[1]==sub[1]} #get a new array of all the elements with this integer
 [same.inject(0){|sum,i|sum+=i[0]}/same.length.to_f, sub[1]] #make a new array of [avg(l),integer]
}.uniq  #remove dupes

dustgun fucked around with this message at 23:24 on Jul 22, 2008

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
http://www.geonames.org/ is a good source of data for such things

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Rails programmers, I have a question:

I have 2 tables, let's say Node(number: integer, owner: string) and Link(up: integer, down: integer) where up and down are foreign keys to Node's number.

I really, really want to be able to go Node.find(x).up_nodes and get a list of Nodes back. Getting the Links back is obviously easy enough, but I can't figure out the right incantation for has_many :through and whatnot to get back a list of the Nodes themselves.

Self-referential queries with non-standard keynames have defeated me :(

dustgun
Jun 20, 2004

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

skidooer posted:

If I understand your problem correctly, you are looking for something like this:
Totally worked (once I set_primary_key'd number)! I wasn't quite understanding what the :source attribute did before.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
edit: nevermind

dustgun fucked around with this message at 15:24 on Dec 10, 2008

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?

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 :-\

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 :(

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.

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!

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I was just about to start playing with merb today but now it feels horribly moot :(

dustgun
Jun 20, 2004

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

Praetorian42 posted:

It might actually benefit to start learning Merb. It'll get you prepared for Rails 3, which, after reading more, might be very heavily impacted by the Merb merge.
My plan is basically to keep on top of edge, and keep the apps I work on up-to-date with the changes.

quote:

Overall, this seems like it is great for Rails people and "Meh?" for Merb people. I haven't seen a Merb person (aside from the Core team) who is particularly excited about this.
It's validation that they were right about their architecture

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
erp, nevermind.

dustgun fucked around with this message at 01:28 on Jan 24, 2009

dustgun
Jun 20, 2004

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

Anveo posted:

Also, I have a legacy table for related products. All it has is a left_id and a right_id. What is the best way to accomplish this in rails? I looked into nested_set and acts_as_tree stuff, but that seems like it might be a bit much for this. I could do a normal join model, but I guess what is throwing me off is both columns will be pointing to the same class (Product).


I had an issue that might be similar - I honestly can't quite tell for sure - that was answered in this thread a while ago.

http://forums.somethingawful.com/showthread.php?threadid=2585949&pagenumber=20&perpage=40#post351829056

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
http://guides.rubyonrails.org/getting_started.html is what I'd recommend at this point. If you need something more realtime than a forum for help, jump into IRC and ask if anyone can help you with sticking points.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Actually, wait. Running scripts and RoR don't go together very well at all because that's not what RoR is really for. What exactly does he want you to do, and are you sure he wasn't just asking you to do it in Ruby?

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
What do you need to tackle? Installing ruby? Installing the gems? Using the script?
Maybe if you take this to the general questions thread you'd have more luck.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Yeah.. whatever you're trying to do, you're doing it wrong.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I'm interested in playing with engines right now, but haven't been able to find any decent guides. Namely I'm looking for someplace that talks about how all the precedence works for adding routes and overriding controller actions.

dustgun fucked around with this message at 02:03 on Jun 24, 2009

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
That's more suited for the general programming questions thread, buuuuut:
code:
File.open('data.txt').each_line {|line|
  (x,y,z) = line.split(' ').map(&:to_f)
  p "x = #{x}, y = #{y}, z = #{z}"
}
Basically, this loops over each line, splits it apart at the spaces, then maps (changes) each of the values to the numeric value. Doing (variable, variable) is a way of assigning values from an array. The whole thing is just a more compact version of
code:
File.open('data.txt').each_line {|line|
  values = line.split(' ')
  x = values[0].to_f
  y = values[1].to_f
  z = values[2].to_f
  p "x = #{x}, y = #{y}, z = #{z}"
}
Hope that helps.

Anyway.

RailsChat time! I think bc2c4a45959be21e6314fba7876b32c1f04cd08a, a commit from the 2.3 branch that hasn't been merged into the 3.0pre branch yet, has badly broken something with cache_classes=false running on mongrel. I spent a nice chunk of my day tracking it down and am just about to sit down and try and write a test case for it. Somehow. Bleh.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Oh duh, I spaced out and forgot about the initial point. Sorry dude.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I did use git-bisect for it (and it was super neat). I had thought it was a problem we hadn't caught with our code, so I didn't bother checking rails until late in the day. Oops.

dustgun fucked around with this message at 15:24 on Jul 24, 2009

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I used to be that way, but after a few years I feel like I can reliably install things on linux :(

edit: sometimes.

dustgun fucked around with this message at 23:39 on Aug 18, 2009

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Assuming you don't want it in the db as anything other than a cache, you'll probably want fragment caching. I haven't used it, but I believe the usage is just
code:
<% cache('name', :expires_in => 60) do %>
  <%= render :partial => "menu" %>
<% end %>
along with
code:
ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"

in your config

dustgun
Jun 20, 2004

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

Myrddin Emrys posted:

This last line is the part that fails, saying:
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:159: in 'require_frameworks': no such file to load - openssl (RuntimeError)
[and then a stack trace or something]

What does this mean? Why is this so freaking hard to get set up and working?
Ugh, that's not a fun issue. Is there another package for ruby available? openssl-ruby or something like that? Maybe libopenssl-ruby ?

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
what does
code:
which ruby
say?

Regardless of if multiple ruby binaries show up for some retarded reason (which is my lame guess atm), I'd be happy to dick around in an irc room or on AIM and get you up and running. I like playing around with new frameworks, but I loathe getting them setup because of crap like this.

dustgun fucked around with this message at 04:24 on Aug 19, 2009

Adbot
ADBOT LOVES YOU

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Hooray. I felt horrible last night when I realized I'd totally spaced out and forgotten about my offer to help out on AIM.

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