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
Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
I don't get the hate for rspec. I love it...

Adbot
ADBOT LOVES YOU

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat
I wanted to like RSpec but after using it for a while I realized my Test::Unit tests were way more maintainable. When it comes down to it all you really need in a testing framework is "assert", the DSL frameworks like Cucumber are just trendy conventions created for and by idiots.

Deus Rex
Mar 5, 2005

Novo posted:

I wanted to like RSpec but after using it for a while I realized my Test::Unit tests were way more maintainable. When it comes down to it all you really need in a testing framework is "assert", the DSL frameworks like Cucumber are just trendy conventions created for and by idiots.

I'm at about ~100 examples written for this app so far and haven't yet encountered many problems at all with RSpec. What makes RSpec specs less maintainable than Test::Unit tests?

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

Deus Rex posted:

I'm at about ~100 examples written for this app so far and haven't yet encountered many problems at all with RSpec. What makes RSpec specs less maintainable than Test::Unit tests?

Nothing. All of the frameworks do essentially the same thing. Just use whichever one you find most readable and the easiest to understand.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat
Right, when I said that my RSpec test were less maintainable than my Test::Unit tests, I literally meant that the way I found myself writing RSpec over time (trying different ways of structuring my assertions, trying to apply DRY, etc) was less maintainable for me than the way I found myself writing Test::Unit tests. Follow your bliss.

rohan
Mar 19, 2008

Look, if you had one shot
or one opportunity
To seize everything you ever wanted
in one moment
Would you capture it...
or just let it slip?


:siren:"THEIR":siren:




Can someone please explain the difference between belongs_to: through: and has_and_belongs_to_many:? This guide says belongs_to: through: is better if I need to actually use the relationship model, whereas I don't have to with has_and_belongs_to_many -- but I need to remember to create the joining table. So, what's the difference? I'd assume if I were making a joining table I'd then be able to use the relationship model, as with belongs_to: through:, so where's the benefit of the latter choice? Is there any way for RoR to create the join table automatically?

(Edit: I think I understand now, but just to be certain: with a belongs_to: through: I need to create another model in Rails, but with has_and_belongs_to: I just need to create a join table in the migrate file / directly in mySQL?)

Secondly, is there a good resource out there for how to use an existing MySQL database with Rails? Everything I've seen assumes I'm setting up and migrating from scratch, but I have the database already set up and populated and just need to know how much of the structure I need to declare for Rails.

rohan fucked around with this message at 08:36 on Sep 1, 2013

kayakyakr
Feb 16, 2004

Kayak is true

Baron Dirigible posted:

(Edit: I think I understand now, but just to be certain: with a belongs_to: through: I need to create another model in Rails, but with has_and_belongs_to: I just need to create a join table in the migrate file / directly in mySQL?)

You are correct. habtm does not have an associated model while hmt does.

Baron Dirigible posted:

Secondly, is there a good resource out there for how to use an existing MySQL database with Rails? Everything I've seen assumes I'm setting up and migrating from scratch, but I have the database already set up and populated and just need to know how much of the structure I need to declare for Rails.

rake db:schema:dump will create a schema from the database. You'll have to create all the models manually.

Peristalsis
Apr 5, 2004
Move along.

Baron Dirigible posted:

Can someone please explain the difference between belongs_to: through: and has_and_belongs_to_many:? This guide says belongs_to: through: is better if I need to actually use the relationship model, whereas I don't have to with has_and_belongs_to_many -- but I need to remember to create the joining table. So, what's the difference? I'd assume if I were making a joining table I'd then be able to use the relationship model, as with belongs_to: through:, so where's the benefit of the latter choice? Is there any way for RoR to create the join table automatically?

(Edit: I think I understand now, but just to be certain: with a belongs_to: through: I need to create another model in Rails, but with has_and_belongs_to: I just need to create a join table in the migrate file / directly in mySQL?)



kayakyakr posted:

You are correct. habtm does not have an associated model while hmt does.

I was confused about this recently, too.

Both habtm and hmt need and use a join table in the database, right - it's just that one doesn't use or require a corresponding Rails model? Also, you have to create the join table in both cases, don't you? I'm assuming that they only point it out in the habtm case because it would be easier to forget it, since you don't have a model for it to remind you of its existence.

kayakyakr
Feb 16, 2004

Kayak is true

Peristalsis posted:

I was confused about this recently, too.

Both habtm and hmt need and use a join table in the database, right - it's just that one doesn't use or require a corresponding Rails model? Also, you have to create the join table in both cases, don't you? I'm assuming that they only point it out in the habtm case because it would be easier to forget it, since you don't have a model for it to remind you of its existence.

habtm is a bit of that Rails magic that you must know about to use. You have to create a table in both cases, and that table must include id's from both sides of the relation. The difference is that habtm doesn't have an id for itself and there is no model for it.

I'd say that hmt doesn't use a join table because that table represents something else in your database other than just a join between the two tables. If the join between the two has no context (ie the only thing you'll ever be doing is joining the two) then the proper relationship to use is habtm. The join table is not really a reminder thing, it's necessary to make the habtm work

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kayakyakr posted:

If the join between the two has no context (ie the only thing you'll ever be doing is joining the two) then the proper relationship to use is habtm.

This is, of course, never true unless it's the simplest throwaway project. Assigning a name, model, and behavior to the relationship between two entities not only provides for future extensibility, but it helps you understand and reason about the relationship better.

prom candy
Dec 16, 2005

Only I may dance

Novo posted:

the DSL frameworks like Cucumber are just trendy conventions created for and by idiots.

You know, it's possible to say you prefer Test::Unit without insulting everyone who likes to use different tools.

Deus Rex
Mar 5, 2005

no this is ruby we have to be insufferable social retards

prom candy
Dec 16, 2005

Only I may dance
Look all I'm saying is there's two ways to write your views: the HAML way and the lovely programmer way.

kayakyakr
Feb 16, 2004

Kayak is true

Cocoa Crispies posted:

This is, of course, never true unless it's the simplest throwaway project. Assigning a name, model, and behavior to the relationship between two entities not only provides for future extensibility, but it helps you understand and reason about the relationship better.

I disagree, but that's probably because I wrote SQL in my past life.

rohan
Mar 19, 2008

Look, if you had one shot
or one opportunity
To seize everything you ever wanted
in one moment
Would you capture it...
or just let it slip?


:siren:"THEIR":siren:




kayakyakr posted:

You are correct. habtm does not have an associated model while hmt does.

rake db:schema:dump will create a schema from the database. You'll have to create all the models manually.
Thanks, that's really helpful. I didn't get a chance to work on it at all today, so I'll see how it goes tomorrow.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

prom candy posted:

You know, it's possible to say you prefer Test::Unit without insulting everyone who likes to use different tools.

Can I still make fun of Windows and PHP?

EAT THE EGGS RICOLA
May 29, 2008

I just switched from a Windows machine doing dev stuff in a Linux VM to a Mac. Anything I should know or keep in mind about doing dev stuff on one? I've never used a Mac before other than just casually.

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord

EAT THE EGGS RICOLA posted:

I just switched from a Windows machine doing dev stuff in a Linux VM to a Mac. Anything I should know or keep in mind about doing dev stuff on one? I've never used a Mac before other than just casually.

The buttons are on the left instead of the right.

Fillerbunny
Jul 25, 2002

so confused.
Get Alfred and take the time to learn the Mac hotkeys.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

EAT THE EGGS RICOLA posted:

I just switched from a Windows machine doing dev stuff in a Linux VM to a Mac. Anything I should know or keep in mind about doing dev stuff on one? I've never used a Mac before other than just casually.

homebrew is a pretty nice thing, but you'll probably end up compiling more things from source than you're used to. I recommend not trying to outsmart homebrew with the permissions it wants (at one point it was asking you to chmod /usr/local). It sounds kind of awful, but dealing with the alternative is much worse.

good jovi fucked around with this message at 02:03 on Sep 5, 2013

xtal
Jan 9, 2011

by Fluffdaddy
Keep using your VM.

prom candy
Dec 16, 2005

Only I may dance
Anyone ever have the absolute pleasure of having to integrate Omniture with their Rails apps? I found a gem for it but it has no documentation whatsoever so I don't know what it does. As it stands we have a lot of Omniture massaging code in our controllers and it just feels wrong. I'm thinking maybe moving the prep code into Javascript and then just outputting the necessary objects into a data tag?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

prom candy posted:

Anyone ever have the absolute pleasure of having to integrate Omniture with their Rails apps? I found a gem for it but it has no documentation whatsoever so I don't know what it does. As it stands we have a lot of Omniture massaging code in our controllers and it just feels wrong. I'm thinking maybe moving the prep code into Javascript and then just outputting the necessary objects into a data tag?

Would encapsulating the omniture "massaging" into models work better?

fart barterer
Aug 24, 2006


David Byrne - Like Humans Do (Radio Edit).mp3
Newbie question: I had trouble getting into RoR a couple years back after casually chatting with some web developers at the company I worked at. I found the path to "Hello, World" a bit too abstract and gave up shortly after.

Fast foward to yesterday and I had a neat idea for a web app, and spent a good part of the night looking into Zend Framework 2 (seriously wtf) and Code Igniter before I remembered RoR. I've been doing some Java game dev in my spare time recently, and I've picked up a lot about OOP and MVC, so it makes more sense now.

But there's only one problem: my site on Lithium Hosting (goon discounts :D) doesn't support anything higher than rails 2.3.18. Here's the environment:

Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.8.25
Rack version 1.1.6
Rails version 2.3.18
Active Record version 2.3.18
Active Resource version 2.3.18
Action Mailer version 2.3.18
Active Support version 2.3.18
Application root /home/blah/blah
Environment development
Database adapter sqlite3
Database schema version 0


A lot of the more recent modules for, let's say security, that I've been seeing in this thread and around the net need at least Rails 3 for the most recent versions, which fix critical security flaws and the like. Can I get away with using an older version of Rails or should I find another way to start developing? Some of the main feature additions to Rails 3-4 sound neat, albeit mostly beyond me.

It actually reminds me of another issue I had, that this community moves so drat fast recommended modules and programming concepts seem out-dated in many of the undated articles I read. It's another one of those things that raise the barrier of entry. Are there any updates guides or wikis on current best practices / gems?

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

androo posted:

Newbie question: I had trouble getting into RoR a couple years back after casually chatting with some web developers at the company I worked at. I found the path to "Hello, World" a bit too abstract and gave up shortly after.

Fast foward to yesterday and I had a neat idea for a web app, and spent a good part of the night looking into Zend Framework 2 (seriously wtf) and Code Igniter before I remembered RoR. I've been doing some Java game dev in my spare time recently, and I've picked up a lot about OOP and MVC, so it makes more sense now.

But there's only one problem: my site on Lithium Hosting (goon discounts :D) doesn't support anything higher than rails 2.3.18. Here's the environment:

Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.8.25
Rack version 1.1.6
Rails version 2.3.18
Active Record version 2.3.18
Active Resource version 2.3.18
Action Mailer version 2.3.18
Active Support version 2.3.18
Application root /home/blah/blah
Environment development
Database adapter sqlite3
Database schema version 0


A lot of the more recent modules for, let's say security, that I've been seeing in this thread and around the net need at least Rails 3 for the most recent versions, which fix critical security flaws and the like. Can I get away with using an older version of Rails or should I find another way to start developing? Some of the main feature additions to Rails 3-4 sound neat, albeit mostly beyond me.

It actually reminds me of another issue I had, that this community moves so drat fast recommended modules and programming concepts seem out-dated in many of the undated articles I read. It's another one of those things that raise the barrier of entry. Are there any updates guides or wikis on current best practices / gems?

You should just use Heroku if you're getting started (http://heroku.com) for hosting. It'll take whatever Rails version you throw at it, and you get a dyno and small database instance for free.

EAT THE EGGS RICOLA
May 29, 2008

androo posted:

A lot of the more recent modules for, let's say security, that I've been seeing in this thread and around the net need at least Rails 3 for the most recent versions, which fix critical security flaws and the like. Can I get away with using an older version of Rails or should I find another way to start developing? Some of the main feature additions to Rails 3-4 sound neat, albeit mostly beyond me.

You could just use Heroku for now? One-dyno + a small database is free.

Molten Llama
Sep 20, 2006

androo posted:

A lot of the more recent modules for, let's say security, that I've been seeing in this thread and around the net need at least Rails 3 for the most recent versions, which fix critical security flaws and the like. Can I get away with using an older version of Rails or should I find another way to start developing? Some of the main feature additions to Rails 3-4 sound neat, albeit mostly beyond me.

Don't use 2.3. With the release of 4.0, 2.3 will no longer be receiving severe security patches. It's a bad idea even before you start tearing your hair out trying to find compatible gems to do anything.

If you're married to Lithium, check with them about your options; most cPanel hosts offer some kind of workaround for cPanel's horrendously out-of-date Ruby and Rails. If you're not married to Lithium, there are a variety of PaaS hosts including Heroku and Red Hat OpenShift that offer free or super-cheap plans at the entry level.

Molten Llama fucked around with this message at 19:46 on Sep 5, 2013

prom candy
Dec 16, 2005

Only I may dance

Cocoa Crispies posted:

Would encapsulating the omniture "massaging" into models work better?

We have some presenters for doing just that but we still end up instantiating them in the controller, whereas I would prefer the controller have no knowledge about Omniture.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

prom candy posted:

We have some presenters for doing just that but we still end up instantiating them in the controller, whereas I would prefer the controller have no knowledge about Omniture.

Could you instantiate the presenters in a helper on demand?

Ruby code:
def omniture_code
  return @omniture_code if defined? @omniture_code

  @omniture_code = OmniturePresenter.new params
  @omniture_code.do_thangs
  
  @omniture+code
end
I usually use this pattern for model finders, but there's no reason you couldn't use it for analytics or any other primarily view-based concern.

You could also use a before_filter I suppose.

Molten Llama posted:

If you're married to Lithium…
…commence divorce proceedings.

xtal
Jan 9, 2011

by Fluffdaddy
Heroku is trash. Don't use Heroku. If you just care about getting your app live and not about system administration (and are comfortable paying a premium for that luxury) use cloud66 or another alternative.

EAT THE EGGS RICOLA
May 29, 2008

I have to write a wrapper related to an api that will be used by complete beginners that are interested in learning, and I'm not sure how to write it so that it's as easy as possible to understand rather than as elegant/ruby-esque as possible.

The annoying part of the api that I'm going to wrap has 5 different types of api calls. wrapping it in one method would require each of the following calls:

api_call - to pull the whole top level db
api_call(var_one) - to pull a sub db based on which top level db was called
api_call(var_one, var_two) - same situation as the previous one
api_call(var_one, var_two, var_three, offset=0, results=100) - this is where it's annoying, the offsets are irrelevant everywhere except for this api call
api_call(var_one, var_two, var_4) - here the parameter names go crazy and they're included in the same api endpoint even though they're not logically related at all

I can write this in one method and have it be confusing to a beginner, then write descriptive methods that reference it and get rid of the confusion while leaving a "magic box" in which will reduce repetition, or
I can write it in a bunch of smaller, descriptively named methods (which will require repetition but which will make each individual method much more easily understood)

What do I do to make it most clear to a beginner? I kind of want to go with the second option but it's really bugging me in terms of repetition.

Also this might make no sense and I might sound crazy.

prom candy
Dec 16, 2005

Only I may dance

Cocoa Crispies posted:

Could you instantiate the presenters in a helper on demand?

Ruby code:
def omniture_code
  return @omniture_code if defined? @omniture_code

  @omniture_code = OmniturePresenter.new params
  @omniture_code.do_thangs
  
  @omniture+code
end
I usually use this pattern for model finders, but there's no reason you couldn't use it for analytics or any other primarily view-based concern.

That's kind of what I was thinking of doing, yeah. On the one hand it's kind of a lot of responsibility for a view helper but I suppose if I offload enough of it into the presenters it won't be too bad. View helpers always feel kind of wrong to me but I mean, these kinds of analytics are a front-end concern so the view is probably the most obvious place for them to go if I'm not going to go full-bore and rewrite everything in Javascript. Thanks for your input, glad to see someone else come up with sort of the same idea :)

hmm yes
Dec 2, 2000
College Slice

xtal posted:

Heroku is trash. Don't use Heroku. If you just care about getting your app live and not about system administration (and are comfortable paying a premium for that luxury) use cloud66 or another alternative.

Heroku is good enough for small projects. It has gotten worse over the last few years, or maybe it's only S3 that has gotten worse, but it's still perfectly fine to recommend.

Cloud66 is really interesting. Can you talk about your experience with it? We run about ~12 apps on Heroku and would consider switching, but we sure as poo poo don't want to be doing any ops.

edit: oh cloud66 is $9/mo per app and not per server, as it won't spin up more than a single app per server. Still cheaper than Heroku but not by as much as I thought. Here I was imagining a big ol' server running a bunch of apps on it, or multiple instances of one app on a single server, but nope

hmm yes fucked around with this message at 05:21 on Sep 6, 2013

Deus Rex
Mar 5, 2005

Heroku is absolutely fine for babby's first Rails site. It's straightforward enough and there are tons of docs and help available for getting set up on it. Since the poster was asking about shared hosting, my impression (please correct me if I am wrong) is that this is a hobby/side project. Cloud66 doesn't offer a free plan so you would have to pay at least $9/mo (or $7/mo amortized if you buy a year of service), whereas the Heroku free tier is definitely good enough for screwing around with until you're more comfortable with Rails and have built something people are actually using.

Unsubstantiated vitriol is pointless and unhelpful and I wish there were less of it on the internet when people ask for help.

prom candy
Dec 16, 2005

Only I may dance
Heroku has done a lot for Rails and other technologies (like Postgres, thanks Pardot!) but I haven't been impressed with their performance. We just moved a client off of $300/mo worth of workers to $50/mo worth of dedicated virtual servers and we're comparable, often better, performance.

That being said their free tier is fine if you don't want to add "learning how to manage a dedicated server" to the end of a long list of things you need to do to build and launch a Rails app.

kayakyakr
Feb 16, 2004

Kayak is true
I've been using amazon's elastic beanstalk, another service that you can get free (for a year). It's ok. I mean, it's pretty poo poo because it's amazon micro, but it's ok and not hard to deploy to.

Molten Llama
Sep 20, 2006

Deus Rex posted:

Cloud66 doesn't offer a free plan so you would have to pay at least $9/mo (or $7/mo amortized if you buy a year of service), whereas the Heroku free tier is definitely good enough for screwing around with until you're more comfortable with Rails and have built something people are actually using.

Closer to a $20/mo minimum. Cloud66 is only providing the management. It's BYOIaaS; you've still got to pay for the Rackspace/AWS/Linode/whatever instances it's managing for you. Heroku's definitely the better (cheaper) option for screwing around.

fart barterer
Aug 24, 2006


David Byrne - Like Humans Do (Radio Edit).mp3

Molten Llama posted:

Closer to a $20/mo minimum. Cloud66 is only providing the management. It's BYOIaaS; you've still got to pay for the Rackspace/AWS/Linode/whatever instances it's managing for you. Heroku's definitely the better (cheaper) option for screwing around.

I'm sticking with Heroku for now, but those other options are interesting.

Thanks for the info, everyone.

xtal
Jan 9, 2011

by Fluffdaddy

atastypie posted:

Heroku is good enough for small projects. It has gotten worse over the last few years, or maybe it's only S3 that has gotten worse, but it's still perfectly fine to recommend.

Cloud66 is really interesting. Can you talk about your experience with it? We run about ~12 apps on Heroku and would consider switching, but we sure as poo poo don't want to be doing any ops.

edit: oh cloud66 is $9/mo per app and not per server, as it won't spin up more than a single app per server. Still cheaper than Heroku but not by as much as I thought. Here I was imagining a big ol' server running a bunch of apps on it, or multiple instances of one app on a single server, but nope

It's a buttload cheaper than Heroku. Adding a DigitalOcean worker is $5 compared to $36, and you just pay a $9 surcharge. It's cheaper and more performant in every possible combination with the exception of Heroku's free tier, which spins down your app after 15 minutes of inactivity. For any website being used by more than its author, that's unacceptable. Plus Heroku lies to their customers and is down all the time and stuff.

But if it is just for the author, then it doesn't really matter!

xtal fucked around with this message at 22:22 on Sep 6, 2013

Adbot
ADBOT LOVES YOU

EAT THE EGGS RICOLA
May 29, 2008

For someone that is new and messing around, which seems to be the case here, Heroku is free.

I wouldn't run something that got any level of traffic off of it, but to play around and maybe easily deploy a prototype?

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