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
jonnii
Dec 29, 2002
god dances in the face of the jews
If you're starting a new project I'd definitely recommend just jumping in to Rails 3. At this point there really isn't any reason not to.

Rails 1.9 is very old, but even so it's not THAT different from 2.x. They didn't take anything away, they just added a lot more, but rails 3 is considerably different from rails 2.x.

Adbot
ADBOT LOVES YOU

NotShadowStar
Sep 20, 2000
It would be okay to learn off of the latest 2.3 Rails, there's a ton of resources and The Book (Agile Web Development with Rails 3rd ed) to help you get started. There's still not a lot of resources for Rails 3 yet and what there are assumes you know Rails 2. That's what I would suggest is to learn from 2.3 and once you've built some things and are somewhat comfortable read up on Rails 3.

And use rvm. Unless you're on Windows, then stop using Windows.

*I even experimented with using gvim and Cygwin for Rails and Sinatra for 2 weeks before I got really, really pissed off at how slow and terrible it was and went full on Ubuntu.

Hammertime
May 21, 2003
stop

8ender posted:

I have an old copy of Agile Development with Rails 2nd Edition. It seems to cover Rails 1.9. Would starting with this book put me in a bad place given that Rails 2 is mature and Rails 3 is imminent? Should I look around online for some Rails 2 tutorials?

Hard choice, from the RailsConf talk by DHH (http://www.youtube.com/watch?v=b0iKYRKtAsA), several of 37signal's products are already running on Rails 3 in production, so it must be pretty drat close to imminent. On the other hand, there's little good tutorials/doc online and I found that the Agile Dev with Rails books were awesome introductions to Ruby on Rails back when I was learning Rails for the first time.

I'd probably use the Agile Dev with Rails book that you have and keep an eye on the new way of doing Routes and AREL with Rails 3, so you know which parts are going to be replaced.

8ender
Sep 24, 2003

clown is watching you sleep
I think I'm going to shoot for Rails2, keeping Rails3 in mind, and just use the book for the concepts while running through the Rails walkthroughs. Any Rails add-ons I should be developing with from the get go or should I just stick to pure Rails?

Coming from a Java background Ruby and Rails is making my brain fry like an egg. Everything is balderdash and seems to operate using very sexy black magic.

code:
website = make_me_a_website(:with_my_stuff_in_it)
website = oh_and_make_it_use_my(database)
put_this_on_my_server_plz(website)

Pardot
Jul 25, 2001




8ender posted:


code:
website = make_me_a_website(:with_my_stuff_in_it)
website = oh_and_make_it_use_my(database)
put_this_on_my_server_plz(website)

Come now, you don't need those parens ;)

code:
website = make_me_a_website :with_my_stuff_in_it
website = oh_and_make_it_use_my database
put_this_on_my_server_plz website

Hammertime
May 21, 2003
stop

8ender posted:

Coming from a Java background Ruby and Rails is making my brain fry like an egg. Everything is balderdash and seems to operate using very sexy black magic.

Learning Ruby plus Rails is a headfuck that won't end anytime soon. It's magic/voodoo all the way down, where ruby starts and rails ends is a big blurry mess. It took me a couple of months of cutting RoR (and delving into the source when curious) to really understand how it all works.

dustgun
Jun 20, 2004

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

Pardot posted:

Come now, you don't need those parens ;)

Don't forget the code cleanup they did a while back
code:
website = make_me_a_website :with_my_stuff_in_it
website = oh_and_make_it_use_my database
put_this_on_my_server_please website

Flobbster
Feb 17, 2005

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

Pardot posted:

Come now, you don't need those parens ;)

code:
website = make_me_a_website :with_my_stuff_in_it
website = oh_and_make_it_use_my database
put_this_on_my_server_plz website

Since I've started using Ruby, I've developed a personal style where if I'm treating a function like a function (assigning its return value to something), I put parentheses around the arguments. But if I'm calling it as a statement, I omit the parentheses. Should I be praised or shamed?

On a side note, I just moved a Rails app I wrote that used RMagick off of shared hosting with a Mongrel to a VPS that I installed Ruby Enterprise Edition and nginx + Passenger on, and I replaced RMagick with Mini-Magick. Holy poo poo :monocle: I can't believe I waited this long to do it, it's orders of magnitudes faster and memory-friendly. The performance is so great now that I think I've overpurchased on the VPS specs, but that just gives me more room to play with other stuff.

8ender
Sep 24, 2003

clown is watching you sleep

Pardot posted:

Come now, you don't need those parens ;)

:psyduck:

I..think I need the parentheses for now. It was hard enough giving up the semicolon and the code is scary without the parentheses :ohdear:

Pardot
Jul 25, 2001




8ender posted:

:psyduck:

I..think I need the parentheses for now. It was hard enough giving up the semicolon and the code is scary without the parentheses :ohdear:

Oh and you probably thought you were joking with the put_this_on_my_server_plz, but if you use heroku.com for hosting, that step is literally git push heroku master.

NotShadowStar
Sep 20, 2000

8ender posted:

:psyduck:

I..think I need the parentheses for now. It was hard enough giving up the semicolon and the code is scary without the parentheses :ohdear:

Once you go black without parens you'll never go back.

Also, yeah Rails does a whole hell of a lot of black metaprogramming voodoo. Much of Ruby isn't nearly that extreme. The internals of Rails 3 is much nicer as the metaprogramming is much toned down thanks to Yehuda Katz's voice of reason.

First Time Caller
Nov 1, 2004

I last used ruby/rails in early 2008 and I've forgotten half of it. In the interests of picking up a job at a couple local rails houses, what's the biggest changes?

What are the recommended books for getting back up to speed? PickAxe 1.9 and Agile Web Dev for Rails, still?

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

NotShadowStar posted:

Once you go black without parens you'll never go back.

It's really not a bad thing at all to start using parens as the rule for methods that take arguments. You should definitely use parens whenever there might be ambiguity (and if i'm not mistaken ruby 1.9 is going to be a bit more strict about allowing ambiguous looking paren-less calls anyway), and even if a statement looks clear now, why not put those parens in anyway for when you'll replace that local var argument with a more complicated expression. It's a good style guide. Just make case by case exceptions for particular :airquote:DSL:airquote: calls.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

NotShadowStar posted:

Also, yeah Rails does a whole hell of a lot of black metaprogramming voodoo. Much of Ruby isn't nearly that extreme. The internals of Rails 3 is much nicer as the metaprogramming is much toned down thanks to Yehuda Katz's voice of reason.

I'm going through a lot of rails 3 now as we're trying to upgrade our app which has a proprietary hacks and fixes in it and I have to to say the new codebase is a thing of beauty. Yehuda undid a lot of the stupid which was kinda grandfathered in from DHH's original coding style which, quite frankly, was suck-rear end newbie poo poo (he can be forgiven for this, he was rather new at it when he first wrote rails). I think at the top of my list is getting rid of the preposterous mechanics of AssociationCollection which goes so hard out of its way to masquarade as an Array for literally no reason other then to make everything a tremendous confusing pain in the rear end. AREL in general is long overdue and is really assuaging a great deal of python envy I've been suffering from.

The only thing they didn't fix and that I still think is wicked retarded is validation and error handling. You're still forced to show some really stupid-looking errors because you can't avoid the whole "attr name + error message" format and it's just a huge pita to translate some very implementation-detail-specific errors into something that would make sense on the user side.

I forget if I ranted about this in here before, but really I've come to the conclusion that model-level validations have been a terrible idea to begin with. I really think think Django is doing the right thing by having primarily just form-level validations on dedicated form objects - makes a lot more sense.

I can't help but blame DHH for this as well because of his misguided opposition to just using the RDMBS for data validation/integrity - it really is where it belongs. Consider validates_uniqueness_of ... it's basically always susceptible to race conditions, unless maybe you use serializable transaction isolation (which can murder your performance). OR you could just enforce uniqueness in the RDMBS and have no problems whatsoever.

So yeah, would have loved to see model validations simply die, get a new form API with validation done there, and make the migration DSL work with db-level constraints (it already does a little.... but could be expanded).

Oh and speaking of migrations, it would also be nice to deal with data-migrations (i.e. actually converting data from one format to another, like calculating a cache field for example) in a better way. It's easy to gently caress up and refer to app-level models form a migration which WILL bite you in the rear end later when your model has changed and somebody needs to run migrations from scratch. That whole approach should just be locked up. Making minimal migration-specific models is the currently prescribed approach, and it's actually not a bad way to go, but there's some neater stuff that could be done like duping your models per-migration number, or maybe simply providing auto-generating minimal-models for you so you can basically use them like raw-sql-but-not-quite.

Hired Gun
Nov 25, 2006

by Ozma
Any ideas on creating multiple records from a single text field? Basically I need the user to be able to copy/paste poo poo from Excel into a text box, and have each line create a new record.

For example, the user inputs:
SMITH
JONES
ADAMS
JOHNSON
PIERCE

And it creates 5 new records with one of the fields being the last name. Even better if they can input

code:
SMITH	JOE
JONES	MIKE
ADAMS	LISA
JOHNSON	STEVE
PIERCE	PAT
And create 5 new records with the tab acting as a delimiter for the last and first name fields. I have no idea if this is even possible, should I attempt it?

Obsurveyor
Jan 10, 2003

Just use a little regex magic:
code:
"SMITH\nJONES\nADAMS\nJOHNSON\nPIERCE\n".split(/\n/).each do |name|
  puts name
end
(this is just to get you on the right track)

Hired Gun
Nov 25, 2006

by Ozma

Obsurveyor posted:

Just use a little regex magic:
code:
"SMITH\nJONES\nADAMS\nJOHNSON\nPIERCE\n".split(/\n/).each do |name|
  puts name
end
(this is just to get you on the right track)
Thanks! That's exactly what I needed.

hmm yes
Dec 2, 2000
College Slice

Hired Gun posted:

And create 5 new records with the tab acting as a delimiter for the last and first name fields. I have no idea if this is even possible, should I attempt it?

I'm pretty sure you could use fastercsv to parse the textarea, if the regex isn't doing it for you. You could also have the user upload a CSV export from excel.

8ender
Sep 24, 2003

clown is watching you sleep
I need some advice on some good Rails hosting. In a few months time I'll be deploying an application that will eventually see about 1000-3000 people using it.

I'd like easy cloud type (or managed VPS) hosting as I don't really have the time to deal with the infrastructure side of things right now. The ease of use and features of Heroku makes my pants tight but not being able to directly access the database and having to use S3 for storing file attachments is giving me pause. Engine Yard looks like it has the same file storage limitations, no email capabilities, but at least allows remote database access through SSH.

Is there any easy to deploy to rails hosts with direct access to db, local file storage, and email capabilities that wont break the bank and that I don't have to manage? Maybe this is too much to ask for.

8ender
Sep 24, 2003

clown is watching you sleep
Looks like a Speedyrails Managed VPS (http://www.speedyrails.com/rails_hosting/vps) might be my ticket to ride. Anyone have any experience with this company?

They're Canadian as well which the boss will like :canada:

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

8ender posted:

The ease of use and features of Heroku makes my pants tight but not being able to directly access the database and having to use S3 for storing file attachments is giving me pause.

I seriously recommend you give Heroku a second thought. Getting your data out is as simple as heroku db:pull or download an app bundle. You don't HAVE to use S3 as your file attachment storage, it's just the most convenient way.

Kimani
Dec 20, 2003

Anime avatar - check
ADTRW poster - check
Defends watching child porn - CHECK!!!
So I'm having a terrible problem that I can't figure out with all the googling I've been doing. The problem is when I try to use Javascript using js.rjs files and stuff. The file gets run but instead of having page.replace_html replace some html, it takes the javascript that gets generated and replaces the whole html with it. I've gotten this stuff to work before, so I don't know what the problem is.

I can replicate the problem with not much going on:

testbed.html.erb
code:
<%= link_to "butt", :action => "testajax" %><br />
<div id="testerror">asdf</div>
main_controller.rb
code:
def testbed

end

def testajax
    respond_to do |format|
        format.js
    end
end
testajax.js.rjs
code:
page.replace_html( "testerror", "rawr" )
When I click the link, the link and 'asdf' div both disappear and are replaced with:
code:
try {
Element.update("testerror", "rawr");
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"testerror\", \"rawr\");'); throw e }
Any ideas? I removed pretty much anything tricky I could possibly be doing, but the problem persists. Whenever I search for other people having this problem, they say something about having some :update thing they needed to remove from their partial. Man, I'm not even using a partial...

NotShadowStar
Sep 20, 2000

Kimani posted:


testbed.html.erb
code:
<%= link_to "butt", :action => "testajax" %><br />
<div id="testerror">asdf</div>

code:
<%= link_to_remote "butt", :url => {:action => :testajax} %>

Kimani
Dec 20, 2003

Anime avatar - check
ADTRW poster - check
Defends watching child porn - CHECK!!!
Ah, sure enough. 'remote' seems to be the word of the day.

Thanks!

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Just throwing this out there, but if anyone's working on an upgrade from 2->3, remember to switch to jquery at the same time. Definitely worth it.

Devian666
Aug 20, 2008

Take some advice Chris.

Fun Shoe

Pardot posted:

Come now, you don't need those parens ;)

code:
website = make_me_a_website :with_my_stuff_in_it
website = oh_and_make_it_use_my database
put_this_on_my_server_plz website

Just started reading this thread yesterday and started having a play around with RoR. I'm trying to figure out when I'm supposed to start coding. I'm also a terrble person because I run on windows.

Sym
Feb 22, 2006
Where am I?

Devian666 posted:

Just started reading this thread yesterday and started having a play around with RoR. I'm trying to figure out when I'm supposed to start coding. I'm also a terrble person because I run on windows.

Windows isn't that bad, it just takes a bit more effort to get a good environment setup. Of the 3 computers I develop on (Work, Home and Laptop) 2 are Windows 7 systems.

NotShadowStar
Sep 20, 2000
You're a more patient man than I. I tried going strictly Windows for Ruby for 2 weeks, had to use Cygwin because a bunch of poo poo doesn't work and there's no such thing as RVM for Windows. I about cracked and was going to start beating homeless until I went 'gently caress this' and went full-on Ubuntu.

I miss OSX, goddamn being poor :(

Sewer Adventure
Aug 25, 2004

NotShadowStar posted:

You're a more patient man than I. I tried going strictly Windows for Ruby for 2 weeks, had to use Cygwin because a bunch of poo poo doesn't work and there's no such thing as RVM for Windows. I about cracked and was going to start beating homeless until I went 'gently caress this' and went full-on Ubuntu.

I miss OSX, goddamn being poor :(

Run Ubuntu in VMWare. Use samba to share your Ubuntu homedir. Edit in Windows. Run Rails in Ubuntu.

(or get a Mac)

Sym
Feb 22, 2006
Where am I?
The laptop is a Mac. I do miss rvm on windows, though I use NetBeans on the Windows machines since I can define multiple ruby platforms and then set them on the project.

Both machines environment is made up of:

Ruby Installer + the devkit (Important for gem installs)
msysgit
Netbeans

libmysql.dll - Since I'm on 64bit I use this to build the mysql gem since the gem doesn't like the 64bit dll

I don't think I've forgotten anything. The Ubuntu VM is a great idea too. I actually did do that for a while. I got bored one day and told myself I would find a way.

Devian666
Aug 20, 2008

Take some advice Chris.

Fun Shoe
I'm starting work on some learning projects. I'm planning on making a basic blog with an article structure and the equivalent of a text adventure but with links/buttons to click for interaction.

I'm still very new to this but are there any retarded things that I should avoid doing? Or any sites that you would recommend to provide guidance for my learning projects?

e: Have I asked the wrong question?

Devian666 fucked around with this message at 01:28 on Jun 25, 2010

NotShadowStar
Sep 20, 2000

Devian666 posted:

I'm starting work on some learning projects. I'm planning on making a basic blog with an article structure and the equivalent of a text adventure but with links/buttons to click for interaction.

I'm still very new to this but are there any retarded things that I should avoid doing? Or any sites that you would recommend to provide guidance for my learning projects?

e: Have I asked the wrong question?

If you meant this for Rails then some general things:

-Rails is MVC and it's your benefit to keep it that way. Don't do queries or other database logic in your templates. Templates should only have very basic logic in them on stuff already done by the controller. Your controllers should be as simple as possible. Push as much logic as you can into models to make your life much easier.

-When possible, use REST. Rails will make your life easier when you do.

-Alternately, don't try and shoehorn every last edge case into REST. It works most of the time, sometimes it doesn't. Don't try and fit the problem into the solution

-Ignore RJS if you're doing Javascript. It's... weird, confusing and I'm not even really sure why it exists. You'll be better served just by doing jQuery or YUI or something straight up. This is easier with Rails 3.

Devian666
Aug 20, 2008

Take some advice Chris.

Fun Shoe
I'd never even heard of REST until now, thanks (I wasn't joking when I said I was new to this).

NotShadowStar
Sep 20, 2000
Read this book

Devian666
Aug 20, 2008

Take some advice Chris.

Fun Shoe
So far I've discovered that the truncate method doesn't work as advertised in the book, and the table output appears to be broken somehow. I am learning a bit by repairing the examples in the book but that's not the easiest way to learn.

I'm also not sure on where the images are supposed to go in the project structure.

e2: no I've found where to put the images. The way he thinks the table alternating colours work isn't how it currently works, which is reason for my confusion.

Still a lot more to learn yet. Including all the mistakes I keep making.

Devian666 fucked around with this message at 07:09 on Jun 26, 2010

NotShadowStar
Sep 20, 2000
That book may have mistakes, I learned from the 2nd edition when it was still being written and it had mistakes. But if you can catch, fix and report the error then you're learning a lot! Also note the book is for Rails 3 so be sure you're running that.

You can also get the previous edition and learn from the 3rd edition book for Rails 2, but you'll have to relearn stuff to go back to Rails 3.

Devian666
Aug 20, 2008

Take some advice Chris.

Fun Shoe
I'm sticking with rails 3 otherwise I'll get too confused as to what I'm supposed to be doing. A lot of things that I've never used before but I seem to be picking up enough for the mean time. Developing my own apps will be the real challenge as I'm bound to mess a few things up on the way.

8ender
Sep 24, 2003

clown is watching you sleep
Just to be sure Apache + Passenger is the preferred setup for new Rails deployments right? Is it really as easy as just uploading the project files?

Obsurveyor
Jan 10, 2003

8ender posted:

Just to be sure Apache + Passenger is the preferred setup for new Rails deployments right? Is it really as easy as just uploading the project files?
I am getting ready to use Apache+Passenger and yeah, it looks this easy to me. You have to add the Passenger stuff to the http configuration and setup an htaccess file per project and then it is just uploading files, I believe.

Adbot
ADBOT LOVES YOU

Colorblind Pilot
Dec 29, 2006
Enageg!1
If you store sessions in ActiveRecord, you can expire them all with rake db:sessions:clear. But if it's a cookie-based store and all the session data is stored client side, it appears that your application has no record of how many active sessions there are. Is that true? Furthermore, how can you clear/expire all the sessions?

Second question that's sort of related: if you want a session to expire after 1 day, what's stopping the user from manipulating the cookie that stores the session hash to make it never expire? Since it seems like no session data is stored server-side, does your app really have no control over it?

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