blog@osd.se

Just another WordPress weblog
  • Home
  • About me
  • My website (in Swedish)

Prototype is a prototype?

August 13, 2007

In my quest to figure out why Prototype’s request method sent all my submit buttons, I stumbled upon this, not so pretty, piece of code:

if (value != null && (element.type != 'submit' || (!submitted &&
    submit !== false && (!submit || key == submit) && (submitted = true)))) {

It’s from a changeset in Prototype’s Trac page and is supposed to fix this bug.

The reason I started reading the code was that I’m using multiple submit tags with different names. Instead of just varying the value, I set the type tag to “submit”. Example:

<input name="create" value="Create New..." type="submit" />

and in Rails I check if params[:create] is set to see if that button was pressed or not. Perhaps this is really bad for some reason that I have missed, I don’t know (it does work in my version of IE6 aswell), but the fix doesn’t solve my problem. It just solves when using multiple input tags with the name submit and vary the name. The reason I don’t like looking what the value attribute is set to, is that it’s part of the design and should be free to change, without having to modify the controller. Of course, hidden values are always an alternative, but requiring Javascript to use a simple form seems wrong.

Anyway, I opened up my prototype.js and started reading the code and found the above piece of code. Note the assignment in the end of the second row. I think it’s intentional.

Comments
No Comments »
Categories
Programming, Rails, Web
Comments rss Comments rss
Trackback Trackback

Oskar on Rails

August 1, 2007

Update : I was going to write a post about the changes I made to acts_as_taggable to get user support, but I just switched to has_many_polymorphs (HMP). I wanted self-referencing tags (being able to tag tags) and HMP provided that with little work. HMP also seems to work directly with will_paginate, which is great. The per user tags weren’t harder to get in HMP than in acts_as_taggable_on_steroids.

Oh the title, I’m so funny! I have to be the first one to ever think of that. Right…

This became another text in English, mainly because the follow up (if I write it) could possibly be useful to more people. We’ll see what happens.

Anyway, about a month ago, I decided to learn a bit of Ruby on Rails. I hadn’t tried Ruby before either, so learning Ruby was/is part of the process, but you can come a long way without having to study the language very deep. Most stuff works as you think they would, after learning the basics. In general I think it’s a nice language, but my knowledge isn’t very good yet.

Rails is wonderful to work with in general. I haven’t really done any web development in many years now (except for some minor WordPress hacking to modify it for my needs, but even that was more than a year ago, and a simple summer course two years ago). Back then I knew a lot less (doh!) and most stuff I wrote was quite poorly written, I realize now, in terms of flexibility and security (Hello SQL injection!). I sure as hell wrote all my SQL statements by hand, though they were quite simple, and in general it usually became quite a mess quickly. I’m sure there existed some projects that the same idea as Rails, but I didn’t know about them then.

Something that is a bit annoying now, is that for my project I wanted two things; tags and pagination (split up something over several pages, to give the user a better overview. Nothing fancy really). As it turns out, the built-in paginate module is deprecated and will be removed in the next version (it’s already gone from Edge Rails) and both the gem and plugin named acts_as_taggable are old and bad, in different ways (they aren’t the same).

The pagination wasn’t hard to solve. I found the plugin will_paginate, which works great. All good. For now…

The tagging wasn’t quite as easy. There are quite a few plugins that tries to (and does) fix what acts_as_taggable did, but better. One is has_many_polymorphs, which is a fair bit more complex and flexible, but I didn’t really need that. The guide he has, on his blog, to use the plugin for tagging is about converting from acts_as_taggable to has_many_polymorphs, which includes a bit more work than it felt worth it for me. I ended up using acts_as_taggable_on_steroids (puh, long name) which is quite simple. It has (or had, I haven’t checked the last version yet) a bug with migrations, but in general it was easy to work with and to work around the bug.

I also wanted to tie my tags to users, because the project isn’t about a community and all user data is private to each user. There’s also a third plugin for tagging, acts_as_taggable_redux, and it has user support already, but it turns out that he ties the tagging (the connection between the tag and the item) to the user instead of the tag. That’s great for community like sites, like last.fm, where all tags are global, but that wasn’t what I wanted. I also found a post about adding user support to acts_as_taggable, but it had the same user connections. Instead I decided that it was easy enough to do myself. I’m not saying that it’s hard, it’s not, but if someone else had done it already and had working plugin, I would rather use that).

It turned out to be even easier than I imagined at first. Rails has some really great tools. After adding a simple user_id column to the tag model, I could do things like

user.tags.find_by_name(tag_name)

which looks great in terms of readability. I might post a summary later on what I changed to get this working.

Now to the real problem: get them to work together. It wasn’t quite as easy to get will_paginate to work with acts_as_taggable_on_steroids. Find_tagged_with works directly on the type you want to tag, but will_paginate does that too. There might be easier ways than how I solved it, I don’t claim to be an expert after just a week (when I did this) with RoR. My solution wasn’t very nice either. I basically runs find_tagged_with, but returns the database request, instead of executing it and returning the result, modify the SQL statement a bit and then use paginate_by_sql to turn it into a paginatable (cute word) object. The correct solution is probably to modify how acts_as_taggable_on… works and extend it with the things needed to paginate the results. If I understand the comments on the acts_as_taggable_on_steroid page, someone might have done that now. I have to read up on that.

Comments
No Comments »
Categories
Programming, Rails, Web
Comments rss Comments rss
Trackback Trackback

Joost – cool but a bit disappointing

May 10, 2007

(This post is based on the content available in Sweden. We don’t get Comedy Central, for example.)

A couple of days ago I got myself a Joost beta invite from GigaOM, so I’ve been testing it out a bit. To start with, I miss sitting in the sofa and relaxing, because my chair isn’t nearly as comfortable as my sofa. I do have a computer hooked to my TV, but that computer runs Ubuntu and I have no plans to change that – at least not just to run Joost. There is a a Linux client planned for Joost, but it’s not yet available. Also, I think Joost gives you a better experience if you have a mouse to control the application with. Even if the available keyboard shortcuts worked well, they didn’t quite cover all my needs. I also missed the relaxing part with TV; just watching and letting someone else decide what to show. Being able to chose between lots of material is not the same as only having a bunch of channels to switch between, but I guess that’s what Joost wants to change too.

Something that they seem to have added more of lately is ads. Not like commercials on TV, but very short ones, lasting just a couple of seconds between the shows. Saying things like “brought to you by hp.com” while showing a blue screen with a hp logo on. There is also this small box popping up in the lower right corner every now and then. I’ve seen a couple of different company logos there and you can actually click the box and it seem to be a ordinary hyper link which opens in your browser.

I watched for a while, but besides some music videos, I didn’t find a lot of material that was interesting to me. Often what seemed to be a interesting program when reading about it, turned out to be a five year old crappy talk show clip, and it was harding knowing what was old and what was new. To guess that “Episode 152″ is older than “Episode 160″ is fairly obvious, but there’s nothing that tells you if it was recorded 1999 or 2006. I couldn’t find any interesting TV shows or movies that I’d like to watch (except possibly Fifth Gear). However, if you do like Lassie, Poker, Indy 500, MTV-like shows, silent movies, fighting and soccer, there’s stuff for you to watch. Unfortunately, I don’t really like any of those.

One should keep in mind that this is a beta version. I hope they add a lot of more content before release, because it’s needed. Rumors say that a release is close, so I hope for their sake that they have time to do it before that. (Their financial part seem to be working at least, because they recently announced a $45 million funding from various companies.)

Unfortunately the content isn’t Joost’s only problem. When I started watching today, some (old) Fifth Gear episodes, it wasn’t smooth at all. The download speed wasn’t fast enough (I have a 10Mbit/s connection and wasn’t using it for anything else at the time), so it couldn’t fill its buffer to deliver smooth sound and video. It kept skipping for the first few minutes or so, then it got better for about ten minutes, and then the skipping started again and continued until I decided it wasn’t worth watching. To start with, I wish they would have used a larger buffer so it would download more data between the buffer underruns. The pauses would of course last longer then, but I think it would have been a better experience. NewTeeVee reports about infrastructure problems with P2P and it could indeed be related to my own problems today. It will be interesting to see how this develop, because the hype in its own will probably keep Joost alive, at least for a while after the launch.

If you want an invite anyway, just let me know.

Comments
No Comments »
Categories
TV, Web
Comments rss Comments rss
Trackback Trackback

Google Reader and MSIE

May 8, 2007

When do Google Reader check for new posts really? Not often enough in my opinion, but I guess that’s what you get if you want someone else to do it. Perhaps it’s time to check out some Firefox plugin or other program to keep track of my RSS flows.

Unrelated to Google Reader, but this made me remember how glad I am that I didn’t bother to expand my own WordPress theme to cover the blog features of WP. IE is a mess to work with (or rather against).

(Yes, www.osd.se does also run WordPress, but not the same installation. I was consider trying to do that, but I decided not to bother. It gives me some extra work on upgrades, but a lot to bother with now. Upgrading WP is usually really smooth anyway. I upgraded www.osd.se from 1.5.2 to 2.1.3 without basically any trouble at all. A third-party plugin needed an upgrade and another was made redundant (static first page). That was it.)

Firefox crashed on me while writing this text. Thanks WP for automatically saving the post while writing and reducing the amount of stuff I needed to rewrite. Shame on Firefox!

Comments
No Comments »
Categories
Web
Comments rss Comments rss
Trackback Trackback

Categories

  • Games (4)
  • Music (7)
  • Programming (5)
  • Rails (4)
  • Stupid (1)
  • Swedish (2)
  • TV (1)
  • Uncategorized (1)
  • Web (4)

Links

  • 456 Berea Street
  • Ayende @ Rahien
  • Calle’s Journal
  • Discobelle
  • Manolo
  • Matthew Garrett’s Journal
  • Maximum Flow
  • MÃ¥nhus (in Swedish)
  • My work
  • MySQL Performance Blog
  • ReadWriteWeb
  • Sphinx search engine
  • The Sartorialist

Archives

  • October 2009
  • December 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox