?

Log in

Sat, Jan. 20th, 2007, 08:28 am
sermoa: Ruby problem

I'm having a problem upgrading to Ruby 1.8.5 on Mandriva. I've downloaded the source, compiled and installed.

When i come to install RubyGems it throws this problem with Ruby:

/usr/local/lib/ruby/1.8/net/protocol.rb:21:in `require': no such file to load -- socket (LoadError)

Why would it do that? I understand that something's missing, but why would it forget to install something so important?

I've just re-installed Mandriva to try to overcome this problem but it just did exactly the same thing again! If anyone knows the answer, i'll be most grateful.

Update: Okay, so i've worked out that 'socket' is a C library, and probably failed to compile for some reason. What do i have to do to make it compile now?

Tue, Jan. 9th, 2007, 03:15 am
leftisto: Attributes > Classes: Custom DOM Attributes for Fun and Profit



Oh, you know you want to:

http://digg.com/programming/Attributes_Classes_Custom_DOM_Attributes_for_Fun_and_Profit

XHTML gives us the ability to extend our markup with customized, semantically meaningful attributes. While the battle between class and attribute might be a holy war to some (and unknown to most others) the fact remains that attribute name value pairs are easier to read and understand, and only attributes allow you to associate a value with your meta-data. Extending XHTML elements in my projects has made me think of how to solve problems in new and better ways. It has made me a stronger JavaScript artisan. In this article, I explain several examples and provide functions for working with your own custom attributes.

Mon, Jan. 8th, 2007, 07:38 pm
sermoa: Processing text boxes line by line

I wonder if anyone knows of a cunning little ruby method that does what i want here ...

I'd like to submit a multi-line text box and be able to process it line by line. Ideally the input would be transformed into an array for easier processing. Is this something we can do? Can we search for \n and split it up that way?

Processing will be done in the controller, using @params[:mytextbox] or similar.


Update: I think i just answered my own question. It didn't take me long to find this:

str.split(pattern=$;, [limit]) => anArray
Divides str into substrings based on a delimiter, returning an array of these substrings.

Sounds perfect! :D

Sun, Jan. 7th, 2007, 09:49 pm
trythil: on has_many :through and workarounds for association callbacks

Hi all,

I haven't seen anything in this community that relates to this, but if this topic has been mentioned before, please point me to the appropriate post(s). The code in my post applies to release candidate 1 of Rails 1.2.

I'm developing an application that is designed to keep track of fan-made videos. One of the associations in the data model is a many-to-many association between Video and Member.

However, there's some additional attributes that need to be stored in that association. Multiple Members can collaborate on multiple Videos, and a subset of those members will be owners of the video -- e.g. have the power to change attributes of the video, add/remove collaborators, and so forth. So I've broken up the many-many association into two one-to-many associations using Rails' has_many :through.

To summarize:

Video, Member, and VideoMember class definitionsCollapse )

This was all well and good until I decided to add some additional associations onto Video to make things more convenient:

Video class definitionCollapse )

This works to read records, but it won't write records properly. For example:
Code snippetCollapse )
Here, is_owner won't be properly set.

The first way I thought of fixing this was to use the after_add callback to set is_owner, but it seems that association callbacks don't work on has_many :through does not generate AssociationCollections.

The only satisfactory workaround I've found so far is to create a new class for the join entity in which the appropriate callbacks get placed:
VideoOwnerRecord class definitionCollapse )
...and change the definition of Video to
Video class redefinitionCollapse )

Similar changes apply to Member.

This gets me the behavior I want, and I can live with this, but I'm wondering if anyone knows a better way to do what is basically specifying different conditions on different associations using the same join model. I'm open to any suggestions, including changing the data model for a cleaner representation (though I'd rather that be the last option :) )

Thanks!

Thu, Dec. 14th, 2006, 07:29 pm
rahmcoff: AJAX history

I'm working on a great big AJAX run website. Now I've come across the problem of retaining history. It doesn't. Does anyone know of some kind of history add-on for Prototype/Script.icio.us? So far nothing I've seen integrates well with it.

Thu, Nov. 23rd, 2006, 07:07 pm
sermoa: XMLHttpRequest and Twitter

Has anyone come across Twitter.com?

I've just discovered it and realised it has a nice API whereby you can basically make a post to it by calling for example:

http://twitter.com/statuses/update.xml?status=my+post&username=sermoa&password=passw0rd

(you may have guessed that's not actually my password!)

I'm pretty sure the variables could be sent via 'POST' and i actually have no interest whatsoever in seeing the XML that comes back - i just want a nice little background thing that you don't even know it's doing it until you go to your Twitter page and see the updates.

A perfect job for XMLHttpRequest, i think! What's more, i'm sure there's some clever little Rails helper that will do it for me ... right? Anyone want to be a darling and suggest how it's done, or point me in the right direction?

I have found something like xml_http_request(path, parameters=nil, headers=nil)
within ActionController::Integration::Session

Trouble is, i don't really know how to go about calling that promising-looking function ...

Tue, Nov. 21st, 2006, 09:38 am
fallenairmen: Sessions on rails

Most of the mini-project is done, all the views/layout are setup, forms are pulling and pushing data correctly. But the few missing things is the user side of form validation... pushing data from a form, to a controller, validating it, and if it's wrong or incomplete pushing that data back to the forms for the user to correct.

My plan is to use a ActiveRecord model to hold the data as it's collected and push it into a session. My question: how can I tell if there is already a session in existence. Once I know if a session/cookie is already present I can react to it, but just trying to figure out the correct way to test. Basically I am looking for the php equivalents to "isset(), defined(), and !is_null()". The last one isn't to hard... 'if myVariable.nil? then'

Also is there a more indepth API document on sessions besides what is mentioned in ActiveBase?

Fri, Nov. 17th, 2006, 03:31 pm
fallenairmen: This is insane...but in a good way

Ruby on Rails is amazing. I am already past my timeline projections for where I should be at in the site development... I don't think that has ever happened in the last 10 years of coding and the last 4 of working professionally.

Fri, Nov. 17th, 2006, 05:25 pm
joeylemur: Fun with ActiveRecord

So, I have the following code in a Ruby script:

The codeCollapse )

And I have the database configured thusly:

The schemaCollapse )

And when I run it, I get...

The errorCollapse )


Anyone have an idea what I'm doing wrong?

skipped back 10