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
enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
The Haml thing is a neat idea, but in practice doesn't everything just turn into div city? There's more than one tag in HTML for a reason.

Adbot
ADBOT LOVES YOU

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

shopvac4christ posted:

http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle - Heckle - This testing utility mutilates your code to see if it will still pass its tests. If it does, there may be something you're not testing completely. It breaks on some things (like any code that sends conditions to the DB), but otherwise is awesome to watch.

What the gently caress? This seems like a lovely and backwards way of doing things. Is it impossible to do any sort of static analysis in Ruby to get actual coverage instead of changing poo poo and waiting for it to break?

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

shopvac4christ posted:

You mean code coverage? Like rcov?

And regarding Haml - you can use all HTML elements. Using semantically incorrect divs is the fault of the programmer.

I saw that you CAN use HTML elements, but the style seems to encourage making everything divs (as does the giant example on the homepage).

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

take boat posted:

Also whatever database you're using must be pretty awesome if it knows how to automatically keep an updated age field :shobon:

Umm, MSSQL and Oracle can both do this - I do think it's better that it's done by the business logic, but it's not exactly a way-out-there feature.

Besides, it's trivial for any even vaguely OOP language to compute a fields value based on the value of other fields.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

take boat posted:

Really? You can fake it in MySQL using views, I know, but do you mean they have an actual age field? I am not exactly up on databases though so either way would not surprise me.

Not age specifically, but MSSQL and Oracle (I'm about 90% sure for oracle) have computed fields. Plus of course you can always use stuff like views.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Nolgthorn posted:

respond_to :html, :xml

bwahahahaha.


Here is a great example of how it works. http://railscasts.com/episodes/224-controllers-in-rails-3

With InheritedResources it gets even more insane. Here's an entire REST controller, that talks HTML, json and xml. It auto-wires up everything to do with manipulating the models provided that your controller and models are named well.

code:
class CampaignsController < InheritedResources::Base
  respond_to :html, :json, :xml
end

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

h_double posted:

Can somebody recommend a good to-the-point guide on setting up a basic blog-style site with Rails?

railstutorial.org is the canonical online tutorial, and a twitter style site really isn't that far off a blog (allow more characters than twitter and don't let everyone sign up for an account)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Pardot posted:

also I hope salesforce doesn't gently caress up heroku :ohdear:

I was at the announcement keynote, and Benioff swore up and down that they're commited to not touching Heroku culture, but really everyone says that and we'll have to wait and see.

One thing that could be interesting is if they pull off database.com and get it well integrated to heroku. One thing that I don't think Heroku has ever pulled off super well is a good database story - it's fine for small stuff but when you get into bigger stuff (particularly at the enterprise level) it's a bit too inflexible for my tastes.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

NotShadowStar posted:

You can use Amazon SimpleDB, RDS or MongoHQ with Heroku if you like, though. Heroku's philosophy is why do something when others can do it much better?

Yeah, that's true. I guess what I'm saying is that I think database.com is a bit more compelling on it's own. It's probably due to working more in the enterprise space, but having a solution for multitenancy baked right into the product is amazing.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Plastic Jesus posted:

I want to use the Linked In gem, but my app also uses Omniauth. Omniauth requires a newer version of oauth than the Linked In gem specifies, and Linked In specifies an exact version rather than '>='. This is easy to fix locally, but it'll break when I push to Heroku since Heroku will download the linkedin gem. Is there any clean way to supply a gemfile when pushing to Heroku?

I had the exact same problem, and fixed it locally and forked the linked in gem and pointed it to my own git repository. You can use mine if you like:

code:
git://github.com/ryanbrunner/linkedin.git
My branches are a bit of a mess though, if you use "new_search" oauth should play nicely with omniauth. Gemfiles take git repositories with no problems, just use:

code:
gem 'linkedin', :git => 'git://github.com/ryanbrunner/linkedin.git', :branch => 'new_search'
To be honest, I think someone needs to take over the linkedin gem. I've had these commits open in a fork request for months now and the gem is starting to get seriously out of date.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
Regarding scopes and where chaining in Rails 3, is there really any significant advantage to using a scope over say:

code:
def self.before_today
  where('created_at < ?', Time.now)
end
It seems a lot cleaner, and avoids some of the issues like evaluating things like Time.now at the point of scope creation.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
I've been in a lot of dev shops that were at that level of errors, untested code and general horribleness, and while it's tempting to say "let's stop everything right now and do nothing but testing / refactoring", a lot of times that really just isn't realistic.

One approach that I've found works well is to set explicit rules about how you're going to deal with technical debt, in a way that you can get buy-in from the higher-ups that it won't grind development to a halt. Here's a good list of rules to start with:

  • Bugs are addressed the way they are right now, but developers need to first create a test that fails due to the bug. This makes regression testing easier (which I'm guessing based on what you've said is a huge problem for your QA department), and after a few months, the hotspots in your code will have decent coverage.
  • New code is developed using TDD.
  • Half a day every week is solely devoted to reducing technical debt. I'd personally handle this by allowing devs to work on whatever they want - they will probably have the best idea where the problem spots in the code are.

Even just 1 and 2 will go a long way to improving your codebase. You'll never have 100% coverage, but if the only areas in your code that aren't covered never change and never have issues, it's far less of a concern in my mind.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Pardot posted:

Unrelated to your problem, but I'd strongly advise against subdomains. They make full stack integration testing much harder than it has to be. And there's not much business value in subodmains. Most people don't know what browser they're using let alone care what the url looks like.

The value in subdomains really becomes a lot more apparent when you get into multi-tenancy problems. If you can segregate / scope your entire data layer based on which subdomain is being accessed, things get a lot easier to deal with.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

Anybody going to RailsConf this week? I'll be at the free Bohconf track Wednesday and Thursday.

I'm there now. Tutorial day was a little dull, looking forward to the keynote today. You should head over to the GitHub meetup on Wednesday, we'll have a beer.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
Yeah, trying to use the ruby supplied by pretty much every package manager is the way of pain and misery. There is literally no good reason to not use RVM.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Dooey posted:

My irb stopper working :(

irb(main):001:0> reload!
NoMethodError: undefined method `reload!' for main:Object
from (irb):1
from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):002:0>

Help please? (On win 7)

Isn't reload! particular to the Rails console? I don't think vanilla irb has anything like that.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
If you're not getting any errors but the partial just doesn't seem to be showing up, the obvious typo to check for is using <% render instead of <%= render.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

ZanderZ posted:

Everything I make is div city. I've tried doing it properly. I've done tables before, but for some reason my clients love the fact that I use divs.

Wow, that has to be the king of blast-to-the-past quoting. I had to use forums search to find where my original post came from, and it's from 3 years before I was actually a Ruby dev :)

For the record, I still like the idea of Haml, but it still puts divs up on an undeserved pedestal. A div tag should be the tag of last resort, not the default. Whenever you use a div, you're basically giving up and saying 'welp, i can't assign any semantic meaning to this thing at all.' Haml really ought to require specifying tags. Sass is the bomb though, particularly in SCSS syntax.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

skidooer posted:

Or congratulate Rails. It automatically adds indexes on join columns when you create your model. :)

Is this new in 3.1 or something? I don't remember it happening on 3.0.8. I assume you have to use :references as your column type, but is there any other trickery needed?

enki42 fucked around with this message at 14:22 on Jul 14, 2011

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

kalleth posted:

Ruby people like one-liners :)

Better still is:

code:
nicks = members.map(&:nickname)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

8ender posted:

I really want to go to the Toronto one but damned if I'm missing paintball day.

If you do manage to come, say hi. I'm Ryan, I'm running the event.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

8ender posted:

drat, now I really wish I could come, especially since I have a developer here thats learning the ropes on Ruby and Rails after years of PHP and this would be some good experience. Unfortunately that developer is the owner of the farm we're all paintballing at.

Its also a bit of a drive as we're all pretty far out in the countryside. Rural Ontario Ruby developers :banjo:

Well, we do run a hack night every second Thursday, and there's Rails Pub Night every third Monday of every month, and a Ruby talks meetup every month if this weekend doesn't work for you :)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
And in any case, you should be using inherited resources and let it do all the dirty nested route lifting for you:

code:
  class ImagesController < InheritedResources::Base
    belongs_to :user, :foo, :baz, :optional => true
  end

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Tomed2000 posted:

Thanks. I have another question that is probably more Rails related, though, so maybe someone can still help. I'm trying to figure out how to use check boxes to select multiple records and update them accordingly depending on what button a user presses (think GMail e.g., delete, archive, etc).

There's a really great Railscasts that introduced me to this functionality but I'm having trouble figuring out how to extend it to include more than one button. He essentially uses a form that includes a checkbox and the button but I don't want to have more than one checkbox! What is the best way to go about extending this functionality to include more buttons without adding the checkboxes?

One thing that a lot of people don't realize is that submit fields actually pass their value through to the server when they submit - I'm imagining you could do something like this pretty easily:

(view)
code:
<ul>
  <%= check_box_tag 'items[]', 1 %> Item 1
  <%= check_box_tag 'items[]', 2 %> Item 2
</ul>

<%= submit_tag "Delete" %>
<%= submit_tag "Archive" %>
(controller)
code:

items = Foo.find(params[:items])

# :commit is the default name of submit buttons in rails.
case params[:commit]
when 'Delete'
  items.delete_all
when 'Archive'
  items.archive_all
end
One caveat - if you're using AJAX to send the form you'll need to set another hidden field called commit manually, since it's not technically the submit button sending the form (even if you hook into the submit event of the form.) It's still a good approach even if you have to do this as it will degrade nicely if your user doesn't have JS running.

enki42 fucked around with this message at 12:35 on Aug 30, 2011

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
In regards to the New Relic "trick", there's an availability monitor on NewRelic that will ping your server every 30 seconds or so - if you turn this on with a free instance, you'll never have enough idle time for Heroku to spin down your instances.

On a related question, does anyone have any hints for speeding up Heroku loadtime immediately after deploys? It's probably the biggest obstacle in our way to being able to deploy fairly continuously, since every deploy means that users are going to see a loading screen for 10-15 seconds.

Also, the migration setup is somewhat weird on Heroku - I'd really like to be able to do database migrations BEFORE deploying code (since 99% of the time they are additive, and code that doesn't know about the new columns will still happily work, whereas the converse is very rarely true.)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

A MIRACLE posted:

I suppose you could pull/migrate/push your db but that's not really a clean solution.

Yeah no, I can't really count on the database not being changed while I'm going through that. I know it's probably an impossibility, it's just more than a little painful to deal with.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
My company does a bunch of stuff like what you're describing, Newbsylberry, and we built a gem for dealing with some of it - https://github.com/bradrobertson/apartment

Basically, the idea with it is that this gem will switch over to different databases (or schemas if you're using postgres on heroku) depending on something like the subdomain of the request coming in (or really whatever you want). We like it a lot better than the scoping thing everyone tends to do since you don't need to add columns like site_id to every table in your app, and once you have things set up, you don't need to think about it (other than running a different version of db:migrate)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

Unless the sites are going to share users, I'd just put each one in a separate Heroku instance and maybe write a rake task that git pushes to each one to deploy. That way you don't have to worry about columns or schemata at all.

Yeah, actually I tend to skip by this approach and it's effective as long as you're not sharing data or have a large number of sites (large being anything more than 5 or so in my experience). We actually used this approach at my company until the number of clients became infeasible to manage separately.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
It really depends on what approach to multitenancy you want to take. If you're using scoping, you will need to make some sort of script that goes through the following steps:

  • Extract a backup from Heroku
  • Import the backup into a staging database on your local machine
  • Set the site id on all multitenanted tables to whatever site id you're working with
  • Repeat for each of your clients

If you're using schemas to seperate data, you could take a similar approach, but move tables to new schemas with ALTER TABLE after moving them over.

In any case, it's not going to be a trivial migration and you should plan for some downtime when doing it.

To be honest, if expanding beyond 5-10 sites seems like a possibility, and particularly if you want some interaction between different clients, I would probably look into using a library from the start. Getting apartment up and running really isn't all that complicated (set up a config file, and remember to use rake apartment:migrate instead of rake db:migrate and you're set.)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

rspec is trash :colbert:

Them's fighting words!

Really though, I've only really ever used rspec, and I like it just fine, particularly once I grokked using subjects, contexts, and it a lot better. What does the newish stuff bring to the table?

Now cucumber, there's a thoroughly useless test framework.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

Also, I like cucumber because I can mash out a high-level view of what I want working with the site to be without giving a flying gently caress about implementation, and I generally don't have to change the feature file once it's written; just implement steps and focus on changing failure messages or making it pass.

I find I can do the same with integration tests written in rspec - you get most of what you need with the capybara DSL and some sort of fixture loading / factories. Adding the seperation between test definition and implementation always felt like an unnecessary step that made grokking the tests more complicated, in my mind.

And yeah, I do agree that even if you understand how rspec works, most of it is just memorization about how you should structure things rather than reasoning about the system.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
I do find that I bump up against the limits of "vanilla" ActiveRecord fairly often, but fortunately, ActiveRecord is built on top of Arel, and there's very little that isn't possible with Arel.

It can seem pretty tempting to drop back to SQL, but you are losing some benefits by doing so - for starters, eager loading associations becomes a lot more of a pain, and you won't be able to chain together any pure SQL calls.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
I think Railstutorial.org starts with scaffolds, but quickly abandons them and starts over within a chapter. It's also an awesome tutorial, and there was just a new version released.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
There should be a menu option in VirtualBox for "Install Guest Additions". I think it's under devices.

Alternatively, just push it up to GitHub or something and clone the repo back down to your VirtualBox.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
I'm shocked that there aren't more people using Sublime Text 2 in here. It's honestly the best parts of every text editor rolled into one super-amazing program. Plus you can get it for every platform. And the dude who makes it is insane and adds features like every night.

Rest of our setup:
- DB: Postgres
- DB editor: pgAdmin (ugh!)
- Text Editor: Sublime text 2
- Server: unicorn / thin
- Gem management: RVM (I really don't get the rbenv fuss, RVM might be coded wonky but it works just fine. I guess if you really like aliasing bundle exec all over the place..)
- Foreman
- Git command line / GitHub for Mac for occasionally checking out some random project.
- Git flow for branching / etc (with the exception that we don't git flow feature finish and use GitHub pull requests instead).

Also, I like cool heroku beta access stuff too :)

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
For those just getting into Sublime text, here's a few tips that turned it from :aaa: to :aaaaa:

  • Command-P (or Ctrl-P on win / linux) is way more powerful than you think. After you've located a file you want, hit ":" to jump to a particular line number in that file or "@" to find a method by its name (works fine for ruby, haven't tried in much else).
  • Command-Shift-P can run pretty much every command that Sublime text is capable of. Just hit it and type what you want to do. I use this all the time with the Git plugin to see a list of changed files, add commits, etc. without needing to leave sublime text.
  • Command-Ctrl-P switches projects (take a few minutes to set up projects, they're awesome.) The amazing thing is you can leave one project and switch to another, and when you switch back, all your unsaved files, open files, etc. are still there and your cursor is even in the same place)
  • Hit Cmd and click in a bunch of places to make multiple selections. This is great when you need to modify the same thing in a bunch of different places
  • If you're in a find dialog, and you need to rename 20 instances of a variable, find it, hit Alt-Enter, now every instance of the variable is selected and you can edit them at the same time.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
One of the only complaints I have with Heroku is that it's exceedingly difficult to do actual seamless deployments.

On a normal setup, you need to push your code before you're able to do migrations, which means that your new code needs to be backwards compatible with an unmigrated database (possible, but much more difficult to do than the other way around, and can tend to lead to spaghetti code).

If you're paying for a dedicated DB, it should be possible to do your migrations prior to pushing up code, but that isn't a cheap option if you're just playing around or experimenting. (we already pay an OK amount to Heroku and haven't needed a dedicated DB set up yet.)

On top of that, even if you can do things perfectly seamlessly in regards to the database, when you do a push Heroku will switch everything over to the new slug before the app has had a chance to fully boot up. If you have a decent amount of gems or something slowing startup time this could be > 15 seconds before you're completely in the clear.

Currently the process I'm thinking of testing out that hopefully should make things completely seamless:

  • Create two heroku applications, live and deployment. Modify deployment to point to live's database.
  • Push all changes up to deployment, and migrate from there. (There is a seam here if the migrations themselves aren't compatible with live, but in most cases like adding columns this is usually fine)
  • Smoke test deployment, and make sure the dynos are up and running.
  • Switch over the domains (on heroku, not DNS) to the deployment application
  • Push to live, smoke test it, and switch the domains back when everything is looking good.

It's definitely a lot of steps, but I think everything could be automated by a script, and as far as I can tell it would be truly seamless for most migrations. Some migrations might require a pre-push to live to deal with the database changing, but I usually find I'm adding columns way more often than I'm deleting them, and renaming could be a "add column, copy data, remove old column on next deploy"

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
Are all of these external contacts children of some other parent relationship? If so, you could base your form around the parent relationship and use accepts_nested_attributes_for on the parent model so you can pass a bunch of external contacts into the parent.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
I think half the difficulty on installing ruby on a mac (or anywhere, really), is that there's inconsistent guidelines and no straightforward, canoncial "hey, absolute beginner programmer, here's what you should do!"

Most beginners are probably going to have to deal with:

  • Starting with the system ruby until someone screams at them about how that's a horrible idea.
  • Downloading XCode for hours unless they were lucky enough to find something on the developer tools that don't require a full XCode install.
  • Hopefully figuring out that they need homebrew and not one of the more old-school package managers.
  • Be utterly confused about why people keep screaming at each other about how either RVM or rbenv are horrible and you should never use one or the other.
  • Hopefully find a recent guide and know that the version of ruby they need to install is 1.9.3.
  • (Fast forward two weeks) Wonder why they include the normal scripts in the first place when every single command ever needs "bundle exec" in front of it.

All of this is pretty much second nature to people who are used to rails, but if you're new to it, there's a lot of different options to consider, and even where there's a clear "right" option, there's still plenty of guides that refer to an outdated old option that should be avoided.

Adbot
ADBOT LOVES YOU

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Pardot posted:

There is literally no reason to ever use mysqlol when you have the option to use postgres.

Postgres isn't a walk in the park your first time either. I open pg_hba.conf and configure it without thinking twice about it now, but the first time I installed Postgres it was a complete pain in the rear end figuring out what was going on.

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