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
Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What's great about Coffescript, and what's wrong with Haml, such that the former is going to be the default in Rails 3.1, while the latter is not?

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Jeez, if you aren't going to learn to write in multiple languages with confusingly distinct syntaxes implemented in crucially differing standards, why not just make a robot and have the robot write the website? :rolleye:

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


It seems like a nice problem to have.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I don't know about everywhere else, but here in SF, Rails seems like the hottest poo poo ever shat.

("poo poo" not intended as a pejorative)

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I found Pragmatic's Programming Ruby 1.9 to be very good at teaching the language from end-to-end, including gem distribution, project structure (the book taught me /bin and /lib :downs:), which a lot of language books seem to assume the reader to already know.

A CS degree is like an Architecture degree: you don't technically need one in order to work on houses....no, wait, that's not right. Okay, being a computer scientist is like being an architect, and being a developer is like being a building contractor: there's a fair amount of overlap between the jobs, and one is more abstract than the other, but they aren't exactly the same thing, and building houses is a business you can join without any specialized schooling at all, as long as you can self-teach and spend plenty of time practicing the craft (hopefully because you enjoy it).

Anyway, you can always just read Structure and Interpretation of Computer Programs off MIT's OpenCourseWare site and know more CS-stuff than 90% of developers.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Any of you fine folks doing something for the Rails 3.1 Hackfest next week?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


8ender posted:

Any idea if 3.1 is going to be dramatically different than 3.0? I'm in the same boat and just to see how bad things were I upgraded one of our 2.3.11 apps yesterday and it was oddly painless. I think I changed one or two lines of code but everything just worked. I was kind of expecting apocalyptic app failure across the board but it doesn't look like all that much changed in the core MVC parts of rails.

I've heard horror stories, but in direct experience, it seems surprisingly backwards-compatible.

I guess my apps just weren't sophisticated enough to break. :shobon:

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


A MIRACLE posted:

Doing a project in rails for work. I have all these .ind files in a tmp directory, do those need to be in version control?

.ind files as in, InDesign? I'm not familiar with the program, but if it outputs html and css, then those are the files that should definitely be checked in. I'd ask your work if they want to save the project files that way as well.

quote:

My office uses SVN :( Should I be using git instead?

I'd say yes, but then, I'm an ideologue. Read up on git-svn and choose for yourself. :)

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Are there any good resources, free or otherwise, on making internal DSLs?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


NotShadowStar posted:

we need to know what you're doing.

Well, at the risk of being outed as one of those "nerd" people: http://www.github.com/njay/tabletop

It's one of those pointlessly ambitious geek proects: make it easier for people to make software tools for or versions of "pen and paper" games by making a DSL for them. Teach Yourself Ruby the Hard and Uncool Way.

There's a lot more I want to do, but I thought that a survey of resources about the field might help me make decisions about what sort of things I should want to do.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


BonzoESC posted:

Your die language is scrub-tier:
Hahaha! Of that, I had no doubt. Hopefully, from such humble seeds the mighty oak yadda yadda. I mean, I do want it to be much more than a die language.


:stare: That's...really cool.

I like how terse it is, but I'm hoping to make something that's as natural-language as I can. The hope is that anyone who makes (or just likes) an RPG could figure out how to describe its rules and procedures with just a commands cheat-sheet and a few minutes thought. For that kind of purpose, I think that "drop_lowest" is kinder than "v". And also I need them to be able to do stuff like "tell me how many dice came up seven or higher, counting tens twice" or "count sets of die values, multiply the size of the largest set by ten, then add the value of the dice in that set" without needing to learn regular expressions.

The results object extending Int is an inspired idea. I thought about making a separate results object for a while, but it seemed like there was too much state to track: you only really know when it's stopped being a "roll" and started being a "result" when the player stops interacting with it, so I just piled everything into the Roll class. :sigh:

If there's no good short-cuts to understanding, I will soldier on.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Yeah, that's basically what I've done so far. BDD 4 lyffe.

I guess was hoping there were articles that could give me some tips like "Be sure to consider factor X, which might not occur to you until you've wasted a lot of time doing something dumb!" But all I found was an article explaining how to use instance_eval to avoid "do |o| o.stuff end" syntax.

I think I need to bring in some other stakeholders. Maybe I'll be able to harass some folks at PAX into doing a focus group.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Newbsylberry posted:

The tutorial has you write different tests, etc. I am thinking of scrapping that aspect of it completely though. It's been incredibly frustrating getting it all to work.

That's a shame. I'm not sure what tutorial you're using, so maybe it's a bad one, but I'm going to go ahead and be dogmatic: writing automated tests, preferably before you write anything else, is one of the most important aspects of web development. It's vital, but it shouldn't be that frustrating: I think something's wrong.

quote:

The stylesheets issue aside, for a while it was giving me errors incorrectly (like it would say my title wasn't "websitename | title" even though checking the rails server verified that it was), so I had to adjust all the versions I was using in my gem file to get it to pass.

Okay, it sounds like you had trouble with a view/integration spec. I'll back off my dogmatism for a second: testing views gets you the worst return for your time investment of all the kinds of testing. I still do it, but I try to not be over-specific. For example, I might test that /projects/1 has a title that contains the project name, using a regex and ".should =~" rather than ".should ==".

But that said, I don't know what your gemspec (e: by which of course I mean your gemfile) has to do with page titles. What do you mean by that?

quote:

Then rake db:migrate wasn't working, because of the version of RSPEC I was using. So it appears that if I'd like to use rake then I won't be able to have accurate testing.

Was this the "expected rake 0.9.2" bug, or something else? The rspec-rails gem uses rake extensively, so they definitely do work together.

quote:

I had an idea for a website a while back and decided to learn how to make it. I think it's a good skill to be able to put on your resume, and I've really enjoyed the process so far. As I get farther and farther along, I realize that to be able to put out a finished product alone I'll need to learn design stuff as well. If I'm going to learn one of the markup and styling languages, which works best with ruby? From what I understand xhtml is the future, would that be best?

Well, you'll definitely benefit from understanding html markup, conventions and best practices. But since we're talking about dynamic applications ITT, your real choice is between template languages which generate (x)html. The default Rails templating language is called ERB, and is basically html pages with special dynamic tags that say things like "print the current user here" or "do this next part once for every item in this list" or "only show this next part when the moon is full".

HAML is the new hotness in templates (today, at least), so you could look into that, but I recommend that you defer learning fancy new things that you don't absolutely have to. Just thinking of my own experience, it's possible to overwhelm yourself if you try to use every fancy new great thing. "Learning Rails" is a multifarious and continuous process towards a rapidly moving target, so it's fine to give yourself to a series of bite-size goals.

quote:

one more question: If I skip testing for the tutorial, is there a book/online guide that can help teach me when to use/how to use testing?

I'm halfway through Pragmatic's "Rails Test Prescriptions," and I'm liking it. I also highly recommend their "The RSpec Book" (much of which is about Rails).

Doc Hawkins fucked around with this message at 00:41 on Nov 9, 2011

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Newbsylberry posted:

Luckily I realized I could simply run a spec file with RSPEC and so just because some of my tests aren't giving me accurate results doesn't mean I have to scrap the whole thing.

The gemfile shouldn't have anything to do with it, but apparently following the tutorial leads to errors that have to do with the version of autotest. It doesn't really make sense to me, but I know that changing between version of autotest, spork, and RSPEC means the difference between passing tests, failing tests, or no tests.

Correct me if I'm misunderstanding the situation: You can alter the version requirements in your gemfile, and then run `bundle install`, and no errors are reported, but some tests are provably false. Alternately, you change the version matchers to something else, and run bundle install again, and the tests start working right, but then you can't run any rake tasks.

If that's all accurate, then I would like to see:
  • Any failed test message of the first case.
  • The error message of the second case.

This is the paid course at railstutorial.org, right? I am in no way trying to shoo you off, but have you tried to contact the author as well? I hope he'd be able to help you with his own guide...

quote:

I think the biggest issue is that I am following a guide, and not fully understanding why it's saying to do what it does.

...but this does not bode well for that hope. Rails is a big stack, like I said, but a truly good end-to-end introduction shouldn't leave you at sea.

Have you programmed any Ruby separately from Rails?

quote:

Maybe it's because the book starts with static pages, but the impression I've gotten is that I'll need to know html and css to deal with the aesthetics of the page. It would be nice if I didn't have to worry about it at all.

My perspective as a grungy back-end guy is that design is really tough: it's something that some people are born with a talent for, which they hone with years of experience, and when I want my sites to look nice, I need to just hire one of those people.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


You'll want to install RVM first, before rubygems. See if that helps.

In an odd coincidence, lately I've been contributing to a set of instructions for that kind of thing.

If you have any problems with the Ubuntu section (besides it not giving working urls for the rubygems packages for 8.04 and 8.10), please let me know: we're going to walk a ton of people through this on Friday, and I want to get out in front of any mistakes or unclear bits.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


When you recommend it, what do you list as its advantages?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Most important question: how do you pronounce it? (I'm partial to "ruh-BENV")

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I'm so there.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Assuming I'm writing my own tasks, is there anything Rake can do that Thor can't?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Is there some way to not need
code:
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)) + '/../lib/')
at the top of my bin files? I see other projects that just start requiring stuff without this kind of hideous declaration, but I can't figure out how they're managing it.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


BonzoESC posted:

Thor's gemspec declares that it wants its lib added to the load path: https://github.com/wycats/thor/blob/master/thor.gemspec#L21

Yeah, I've got that in mine, too.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


prom candy posted:

Do you guys use postgre in production as well or just for development?

When people say "use postgres in development," it's short for "use exactly the same environment in development as in production, by the way use postgres."

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I think you are. Unit testing seems relatively popular in Ruby development. Ruby has two unit testing frameworks built into the standard library (well, one and a half), and there's a handful of others that people use. All you have to do as far as dynamism is test behaviors rather than identities: expect a returned object to respond to some methods, rather than have the class MethodResponder or whatever.

Also, tell me isn't a real example:

quote:

use Ruby on Rails on Cake PHP on Gentoo Linux

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Doc Hawkins posted:

"use exactly the same environment in development as in production, by the way use postgres."

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Physical posted:

MySQL is sweet and no real business is going to use postgres (right)?

Please don't troll.

Physical posted:

Even in my development environment I want it to be as close to production as possible, and that means using the respective database type. I thought this was the norm.

It is. That's why we're talking about installing postgres locally. But maybe you misunderstand: you're supposed to choose the database based on what you want to have in production, then install the same one in dev, not the other way around.

Doc Hawkins fucked around with this message at 15:53 on Mar 30, 2012

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Physical posted:

I'm not trolling. I said (right?) to ask for confirmation but I guess me not knowing everything there is infuriates you to the point that I must be trolling.

"Infuriate" is a very strong word.

quote:

I actually think you misunderstand because that is exactly what I said.

Suffice to say, there are reasons to prefer Postgres to MySQL, but if you've never run into or heard of them, then I guess there's no reason to change.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


prom candy posted:

If you want a list of methods on an object you can just write <your obj>.methods but it bubbles all the way up to the Object object, so you get a lot of methods that you don't care about.

code:
no_inherited_methods = any_object.public_methods(false)

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


The question of whether to teach people Rails first and then how to TDD it, or to teach it all at the same time, seems destined to be a perennial one.

Today, I'm leaning towards the latter, including acceptance tests of the sort that cucumber is used for, but I don't necessarily recommend cucumber itself: for rails I mostly make request specs using rspec and capybara. And recently I've heard of turnip, an rspec extension that interprets the same Given/When/Then language cucumber does.

When I was learning this stuff, I think I got a good start from The Rspec Book (despite the name, covers cucumber, I swear). It hasn't been updated in a while, but (1) if you buy from Pragmatic, you get all future updates for free, and (2) relishapp.com/rspec will catch you up with any changes real quick.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I think that past a certain scale, it's easier to run an app as a network of independently scalable single-purpose services than a single monolithic Rails project.

I also think that maybe twenty companies in the world have projects which have reached that scale.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I have made a lot of oddly-named app subdirectories in my time, and I have never had to explicitly add them to an autoload config. Maybe that's only for lib/?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I didn't quit my job quite early enough.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


jetviper21 posted:

You can always do a params.inspect to dump out all the params in your view as for local variables are you referring to helper methods or the instance variables you define in your controller actions?

For instance variables, try: http://rubydoc.info/stdlib/core/Object#instance_variables-instance_method

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What would keep you from just migrating to something else if you didn't like the price?

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


For loops are training wheels for java babies.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!



As with almost any programming language construct, you don't have to learn everything about how .each works to use it effectively.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What worked for me was choosing a domain I found interesting and test-driving a library that modeled it.

e: me rite gud

Doc Hawkins fucked around with this message at 17:32 on Mar 1, 2013

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Build is a method on associations, not on models. It basically calls `Thing.new(thing_haver: thing_haver_instance_on_whose_things_association_we_called_build)`.

You might prefer an instance method on the class which holds the association.

Ruby code:
class ThingHaver
  has_many :things

  def build_named_thing(full_name)
    name = full_name.split(' ').first
    things.find_or_initialize_by_name(name)
  end
end

Doc Hawkins fucked around with this message at 16:30 on Mar 14, 2013

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Well, there is no method `find_by` in rails, though there are the dynamic finders `find_by_*` for each attribute an AR model has, and `find_by_attributes` which would work with arguments like `(name: name_variable)`.

I'm actually not sure if those methods return chainable scopes (probably?), but `where` definitely does, and you can use it to write class methods that can chain, be chained upon, and be called on associations.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


How many is "a bunch", and how varied are they? It's not an intractable string processing problem, especially if you know "success" would be "a constant of this name already exists", because that'd be easy to write tests for, so with a database dump of the current values you could home in on a solution pretty quick. The worst case would be needing a full lookup table, but even that would only be temporary. The more important thing is to change your serialization to read downcase and snake-case but write only in snake-case.

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Steely Dad posted:

I want to obfuscate IDs in my URLs without having to either change my primary key types or add slug attributes to my models and use those. In the past, I've used the hashid gem for this and it worked well, but I see it hasn't been maintained in 4 years. Anybody else know of an actively maintained gem they like for this purpose?

from that link it looks like they renamed the project to "sqids", which is maintained

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