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
Pardot
Jul 25, 2001




shopvac4christ posted:

gently caress that HTML poo poo, Haml is where it's at.

Haml is awesome. We use it at my company and it's just great. I wish we could use sass too, but our designers need to make changes to the css often and don't understand it :smith:

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




Space Kimchi posted:

Also a lot of the AJAX stuff is nice but good lord is it black magic.

Start with using the rjs templates and what not. Then start to actually learn Javascript and Prototype. I'm on the second step currently, and while I might not be the best javascript guy, I know what's going on and it doesn't feel like black magic anymore.

And if you ever are wondering why something works the way it does in rails, start reading the rails source code. It's not that scary, I promise. :)

Pardot
Jul 25, 2001




Space Kimchi posted:

Oh god MVC :psyduck:

I don't think making it a helper is the right thing to do. This either wants to be its own class which would live in app/models (if you wanted to be all restful about it) or a class in lib.

Pardot
Jul 25, 2001




How about some sort of digest (md5 or sha2 or whatever) of their email address and some random salt you store with the address?

Pardot
Jul 25, 2001




Trabisnikof posted:

That's what I use for a similar requirement.
code:
def hash_email
    d = Digest::SHA1
    salt = "salt salt salt?"
    d.hexdigest( self.email + salt)
  end
Shouldn't have to really worry about collisions and since I'm not using MD5 it will be unlikely someone will rainbow table it.

If you're worried even in the slightest, just store a new random salt for each email address. That would prevent any sort of rainbow tables and isn't hard to do at all.

Pardot
Jul 25, 2001




Trabisnikof posted:

Actually, that is a good idea. Although, isn't that still weak to Rainbow Tables, just each hash requires a new lookup? I may not have my concept of Rainbow Tables right though.

No, they would have to make a new rainbow table for each salt, which makes the whole reason to make a rainbow table worthless.

Pardot
Jul 25, 2001




Also keep in mind that even when you get this working, it's really not the best way of going about it. Every time they click the show/hide button, they are being sent to the server to get the 1 line of javascript to do the show or hide. This should be done as an inline js function, allong the lines of:
code:
link_to_function "comments" { |page| page[:comments_11].visual_effect :toggle_blind }
Edit: Only hit the server when you have to go and get (a lot of) new data, or update things, as it's relatively expensive to do. For something like blog comments, all of them should be sent with the blog post, or at least the first page of 40 or so.

Pardot fucked around with this message at 21:25 on Nov 18, 2007

Pardot
Jul 25, 2001




zigb posted:

Apache/FastCGI/RoR

Is there a reason you're not using mongrel?

Pardot
Jul 25, 2001




poemdexter posted:

I'm still new to both Ruby and the Rails gem.

I would really recommend using edge rails over gem rails. You get to take advantage of all of the new improvements and such. And rails 2 is due out soon anyway.

My favorite way to do it is to check the trunk out into your own repo using piston. It's a lot nicer than svn externals.

Pardot
Jul 25, 2001




MrSaturn posted:

classic_pagination

Instead of that, which was taken out for a reason, give this on a try will_paginate:
http://errtheblog.com/posts/47-i-will-paginate
http://errtheblog.com/posts/56-im-paginating-again

just do piston import svn co svn://errtheblog.com/svn/plugins/will_paginate vendor/plugins and try it out. If you don't like it then go back to classic. Piston, assuming that you're keeping your stuff in a svn repo.

edit: here's a screencast on it: http://railscasts.com/episodes/51

Pardot fucked around with this message at 07:49 on Dec 24, 2007

Pardot
Jul 25, 2001




Keep in mind that 1.9 is a development release, not intended for production. Check out Ruby 1.9 right for you?

On the issue of VMs, there are a few alternate ruby VMs being worked on
http://rubini.us/ - talk at rubyconf
http://jruby.codehaus.org/
http://www.ironruby.net/

They're all a little rough around the edges, from what I hear. I admittedly haven't tried any of them. However, rubinius seems the coolest, as it tries to be written in ruby itself as much as possible.

Pardot
Jul 25, 2001




SeventySeven posted:

migrations

The 'right' way to do to, is what you say. You should write a new migration to undo the stuff you no longer want.

It is possible to flatten them, if you'd like, but you're going to have to clear your database and start from migration 0. This is fine when you're first starting the app, I feel. But as soon as you start having real data you can't do this anymore. You need the migrations to

When you roll out the app, you should make sure it passes all your specs, make a tag, and release from the tag. I'm assuming you use rspec, write tests, and use subversion. Not to get preachy, but you should be testing everything, and using source control. I guess you could use something other than rspec, but it's pretty awesome. As for subversion, it's fairly ubiquitous, but a lot of the cool kids are using git now. I've not used that though, so I don't know if there are still tags and such but I'd assume so.

That said, you should also take a look at auto migrations. It's pretty slick. I haven't had a chance to use it yet, but I probably will for the next app.

Pardot
Jul 25, 2001




El Cheeseman posted:

Apparently just after I posted this code, it started to work fine.
Sorry.

The controller is not at all where you want to have anything to do with presentation stuff, that belongs in the view. You want to look up partials and content_for.

content_for: http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html

Your controllers really only should take in params, and use them to pass an object to your view. Read the popular Skinny Controller, Fat Model, even though that's aimed at not putting model stuff in your controller, same goes for view stuff in the controller.

Also stay away from class variables. Not that they don't have their uses, I can't remember the last time I had reason to, and they shouldn't be used for what you're doing.

atastypie posted:

What's the correct notation when referring to an action and the controller it came from?
I use UsersController#index. Same as ikari.

atastypie posted:

Does anyone have any book recommendations on getting started in testing, specifically within a rails environment? The two books I have found are 'Foundations Of Rspec' and 'Agile Testing With Ruby And Rails', but I don't know much about either.
I can't help you with books. David Chelimsky just posted that he contributed to advanced rails recipes, though.
Here is a video from ruby conf with him: http://rubyconf2007.confreaks.com/d3t1p2_rspec.html
And here is another testing video:
http://rubyhoedown2007.confreaks.com/session01.html
I do really like rpsec and even contributed a (very small, pair programmed with someone else) patch to it :)

smackfu posted:

rails shared host
I'm using apisnetworks for my personal stuff now, and they've been the only host I've stayed at for more than one year in the last 8 years or so. Goon run for what it's worth, you can get some discount in the thread in sa-mart. The only problem I had was trying to run mingle on it because it was using a half gig of ram. I have no idea why it takes so much, maybe it has to do with jruby. If you decide to use them, let me know.


edit:

I'm starting to take a closer look at merb and would also like to check out one of the other ORM (datamapper or sequel) at the same time. Has anyone used any of that? Should there be a new thread for this or the general ruby thread?

Pardot fucked around with this message at 06:38 on Jan 5, 2008

Pardot
Jul 25, 2001




I've used acts_as_solr before. What's the difference between ferret ad acts_as_solr? They both use lucene if I'm not mistaken.

MrSaturn posted:

horay =/

I guess what I want to know is how do I set up my .htaccess to default to that running application... if I point to public/dispatch.fcgi nothing ever loads.

code:
RewriteEngine On
RewriteRule ^(.*)$ [url]http://127.0.0.1:some_port/[/url]$1 [P,L]
Then have a mongrel running at some_port. Don't use fcgi.

edit: They don't let you install gems?

Pardot fucked around with this message at 06:38 on Jan 9, 2008

Pardot
Jul 25, 2001




There was mention of Active Couch, which is an active record wrapper for couchdb on the rails envy podcast today. I haven't used it myself, but it could be worth looking at.

Pardot
Jul 25, 2001




Registration for railsconf just opened up the other day. http://www.railsconf.com/

quote:

The content this year will also take a step up in terms of experience required for many sessions. Less “I’m just getting started, how does it work?” and more “I’ve been doing this for a while, how can I become better?”.

A good number of the sessions are already announced, as well as the tutorials. But the keynote names are still being pinned down. And we’re also reserving some session slots for emerging topics as we get closer to the conference.

Pardot
Jul 25, 2001




For those of you who rSpec, is there a good way to set expectations on #initialize? I was doing this, but it seems dirty:

code:
describe Clock do
describe "#initialize" do
  it "should start ticking"
    clock = Clock.new
    clock.should_receive :start_ticking
    clock.__send__ :initialize
  end
end
end

class Clock
  def initialize
    start_ticking
  end
  def start_ticking
    puts "tick"
  end
end
I've since just refactored out the initialize method, but there still seems like there should be a better way then to call initialize a second time.

evildoer posted:

Is there a method to move up just one directory in Ruby?

I'm not sure what exactly you want to do, but look at FileUtils maybe? Also if you're using ruby to do command line stuff, you should look at making Rakefiles.

Pardot
Jul 25, 2001




Oh, I like that idea. I'll have to keep that in mind.

My class actually is an importer that uses some api. I was setting up an api connection in initialize, but I've since refactored it so that there's a method that makes the api connection only if there isn't already one. Then each method that needs a connection calls ensure_connection.

It also works well because I can stub that method so it doesn't actually go out and make the connection.

Pardot
Jul 25, 2001




Hop Pocket posted:

Hooray for hourly backups

Are you not using source control?

Pardot
Jul 25, 2001




In case some of you missed this, there's a new version of rubygems, 1.1.0, out. It's supposed to be much faster at indexing, but I haven't had a chance to test it out yet. Just run sudo gem update --system to get it.

http://blog.segment7.net/articles/2008/03/29/rubygems-1-1-0

Pardot
Jul 25, 2001




Hop Pocket posted:

I'm on leopard, and I had to run

code:
$ sudo gem install rubygems-update
$ sudo update_rubygems
To get it to run. Both finished the same way, with a weird error message at the end, but only after trying the above way of updating did `gem -v` == 1.1.0

You know, I read some blog comment that someone else had to do this too, but I just did clean install of leopard on my macbook and the regular gem update --system worked fine. That was using the ruby that came with it, not macports or anything. I wonder what causes the difference.

Pardot
Jul 25, 2001




The new timestamp migrations in edge rails is cool and solves the problem of two people checking migrations with the same number (though you should update your copy before checking in and notice this anyway :argh: ). It might solve my biggest issue with migrations, too but I'm not sure -- I'd have to try it out. It's when you branch for a release and continue working on trunk, and then have to fix something on your branch right away that involves a migration. What I've done before with that is to flatten the migrations down to a single migration before the branch, then skip several numbers for the next trunk migration. Ugly.

The other awesome edge rails thing is the gem dependancies. You specify what gems you need in environment.rb
rake gems:install - installs all the gems your app needs
rake gems:unpack - vendors all the gems

Pardot
Jul 25, 2001




You don't need to use counter variables anymore, or define arrays, or use while loops or for loops anymore now that you've entered the magical world of ruby!

Here's a quick refactoring of your code. I don't really like how you were using regexes to generate the account name, but I didn't want to figure out a different way to do it.


http://pastie.org/185316

I put it in as a picture for the syntax highlighting, to see how I'd like it. I think it works well for short-to-medium length stuff like this.

Pardot
Jul 25, 2001




Sewer Adventure posted:

Is session data stored in the cookie by default? Is that why there is a 4kb limit?

Yes and yes. Cookie based sessions were made the default in revision 6184 back in February 2007.

r6184 posted:

Introduce a cookie-based session store as the Rails default. Sessions typically contain at most a user_id and flash message; both fit within the 4K cookie size limit. A secure hash is included with the cookie to ensure data integrity (a user cannot alter his user_id without knowing the secret key included in the hash). If you have more than 4K of session data or don't want your data to be visible to the user, pick another session store. Cookie-based sessions are dramatically faster than the alternatives.

What are you doing that needs more that 4k for the session? Typically you shouldn't store entire objects in the session. Rather, store the id, and then do Model.find session[:whatever].

Pardot
Jul 25, 2001




You may also want to take a look at the Complex Rails Forms series at railscasts.

http://railscasts.com/episodes/73
http://railscasts.com/episodes/74
http://railscasts.com/episodes/75

Pardot
Jul 25, 2001




dustgun posted:

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

This may work for you:

code:
[b]>> s = "\xC2\xAE"[/b]
=> "\302\256"
[b]>> s.to_[/b]
[i]s.to_a    s.to_f    s.to_i    s.to_s    s.to_str  s.to_sym  [/i]
[b]>> require 'activesupport'[/b]
=> true
[b]>> s.to_[/b]
[i]s.to_a        s.to_date       s.to_datetime     s.to_enum             s.to_i             s.to_json
s.to_param    s.to_query      s.to_s            s.to_set              s.to_str           s.to_sym
s.to_time     s.to_xs         s.to_yaml         s.to_yaml_properties  s.to_yaml_style    s.to_f[/i]
[b]>> s.to_xs[/b]
=> "&[i][/i]#174;"

Pardot fucked around with this message at 01:32 on May 26, 2008

Pardot
Jul 25, 2001




Anyone going to be at railsconf?

Pardot
Jul 25, 2001




Cylon Dinner Party posted:

Thanks! You came through where my google fu failed. Please accept my apologies, if the Rails thread is not meant to double as Ruby Stupid Questions.

I mentioned this in the merb thread too, but I think a general ruby megathread would be better. I'm sure the tread would be just like this one, mostly rails but some random ruby stuff.

Maybe we should just get the name of this thread changed.

Pardot
Jul 25, 2001




unleash the unicorn posted:

So I've been playing around with Ruby lately, did all the Lucky Stiff stuff and so on, and now that that's been going great I was wondering whether it's possible to make something I created with Shoes into a "real" .exe-File.

Is that even possible with ruby?

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

Pardot
Jul 25, 2001






Oh no! It all works fine on iMacs at work – no spec failures or this out of memory stuff, but my poor old macbook just can't handle it. Probably an issue with my ruby or something, but who knows. It's kinda funny just how bad it broke.

Pardot
Jul 25, 2001




I don't think that's all of the specs, because it blew up. There are a few old tests too that are slowly being moved into tests. On the dev machines, the tests+specs take about 5-6 minutes I think. That defiantly needs to be sped up. There are also about 15 min worth of selenium tests, but usually you just let the ci box run those, except for the ones you know you're hitting. The ci box is an old mac mini, and poor thing takes like 50 min to run through the specs, tests, selenium, and javascript tests.

Why so many? It's a very large and complicated app. We have something like 10k lines of code and 35k of tests, though I don't think rake stats counts some of the stuff. Some could argue that it's overkill, but it just happens that way because of BDD.

Pardot
Jul 25, 2001




Mr. Wynand in the linked post posted:

One thing that (IMO) causes a lot of confusion (in a general sense) is how .errors[:whatever] can sometimes return an array of strings, and sometimes just the string. NOTHING ELSE EVER DOES THIS IN RUBY. EVER

Spot on. I hope this gets merged in. I came across a thing with AR's sql generation that I may write a patch for. I wasn't sure it'd be worth it, but if you say there'll be blowjobs, than it just might be!

Pardot
Jul 25, 2001




Tziko posted:

Just a heads-up: Rails-doc 2.0 was released today. The update includes multiple improvements, including documentation for the different versions of Rails. Hopefully it'll shape up to be the php.net of Rails...

Hooray, I asked them for hi res icons to use with Fluid, and they did http://rails-doc.org/about

Pardot
Jul 25, 2001




bitprophet posted:

Does Ruby have a pretty-print module of any kind?

yes

code:
>> a = %w[just a regular array whoo]
=> ["just", "a", "regular", "array", "whoo"]
>> b = [a, a*3, a]
=> [["just", "a", "regular", "array", "whoo"], ["just", "a", "regular", "array", "whoo", "just", "a", 
             "regular", "array", "whoo", "just", "a", "regular", "array", "whoo"], ["just", 
              "a", "regular", "array", "whoo"]]
>> require 'pp'
=> true
>> pp b
[["just", "a", "regular", "array", "whoo"],
 ["just",
  "a",
  "regular",
  "array",
  "whoo",
  "just",
  "a",
  "regular",
  "array",
  "whoo",
  "just",
  "a",
  "regular",
  "array",
  "whoo"],
 ["just", "a", "regular", "array", "whoo"]]
=> nil
edit: table breaking

Pardot fucked around with this message at 02:12 on Jul 21, 2008

Pardot
Jul 25, 2001




Nolgthorn posted:

Making plugins is hard, would something this complex be better as a generator? Would that be any easier or more useful than having it as a plugin?

Having plugins that have views and stuff is hard in rails. There is something called plugin engines that do that, but it got some hate in 2006 from dhh, and I'm not sure what the current state of the project is.

Generators could work, it really depends on how complex what you're adding is going to be. It seems like it would be a pain.

Merb has something called parts slices, which do exactly this, and it's built into the framework. I've not used them myself though. If you're going to have more than one of these plugins, it may be worth rewriting to merb.

---

This has more or less become the ruby megathread. What do people think of getting the title renamed?

Pardot fucked around with this message at 04:27 on Jul 24, 2008

Pardot
Jul 25, 2001




Yeah, I never promsied it'd be pretty :shobon: Keep us updated on what you decide.

Carabus posted:

Wow thanks, I wasn't expecting that. And it's easy to follow.

http://www.ruby-doc.org/core/classes/Enumerable.html – Learn all the stuff enumerable buys you. This mixin has all of my favorite ruby methods, by far.

Pardot
Jul 25, 2001




B1axident posted:

Not sure if this is the best place to ask, but I can't search for a Merb thread!

But I've been coding in Rails for a while now, and am getting interested in Merb and have seen it mentioned a few times in this thread. So does anyone have any good tutorials for Merb. Also is Merb functional enough to actually use it to produce sites?

There was actually a merb thread a while back, but this thread is fine. The main site is at http://merbivore.com/ and that gives you instructions on getting it. If you'd rather go edge than gem merb, you want to pull from wycats branch.

Merb is a bit different, in that the only thing you actually need is core. You'll want to get more and some plugins, but you don't need them, necessarily.

A good site for learning that came up recently is http://merbunity.com/. The irc channel is good too. There are a few people using merb here, so this thread could probably answer some questions.

Also check out datamapper.

Pardot
Jul 25, 2001




What you're going for is a named route. Try map.login '/login', :controller => 'users', :action => 'login'

However having a login method on UsersController isn't RESTful. It's common to have a sessions controller, and new gives a login form, create makes a session (logs in), and destroy logs out.

--- edit:

We had a really weird problem yesterday. We upgraded rails to 2.1 and rspec to 1.1.4. There are 3 tables that have plural names and plural models, and so the fixture files are plural too. Now any spec that had fixtures :all, rails would go looking for all of the classes based on the fixture file names to load them. It couldn't find these three because of the break in the naming convention. There is set_fixture_class on Test::Unit::TestCase which the rspec example inherit from, but this happens before that comes up.

The problem is that we have a huge number of specs, and to run a full suite, it would look for these 3 classes, 18 times per file, causing it to just print stack traces to the log for almost 2 minutes before running the specs. The specs ran fine, because the fixtures in question are just empty files to get rails to clear those tables in integration tests (which is a whole other reason why fixtures suck...).

The solution? Dependencies.loaded << "#{RAILS_ROOT}/class_name_without_an_s" in spec_helper to trick rails into thinking that it was already loaded, and that it didn't need to go looking for the nonexistent file.

Pardot fucked around with this message at 19:26 on Aug 2, 2008

Pardot
Jul 25, 2001




wunderbread384 posted:

It's stupid, but one of the many downsides to Rails being "opinionated software" is when their opinion is wrong.

You have to admit though, that there are also a ton of benefits to opinionated code. Like not having pages and pages of configuration files and getting methods thrown in because you name things a certain way, and so on.

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




Panic! at the Fist Jab posted:

So what's the buzz on Sequel? It looks really awesome but I don't hear any news about people using it in any projects.

I think datamapper is drawing most of the non-active record users. Of course, non-ar isn't exclusive, but sequel really seems like the 3rd party candidate.

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