Posts Tagged ‘ruby on rails’

sortable_element, acts_as_list, and GUID plugin

Sunday, April 20th, 2008

Briefly, I just wanted to jot down some notes that might help some else working with any of these rails tools:

  • sortable_element: This is a method in the ScriptaculousHelper, which will easily allow you to implement a drag and drop list.
  • acts_as_list: A rails plugin that will manage an order list of relations. This will add move_up and move_down as methods in your model. It is quote convenient.
  • GUID: A rails plugin that will turn your activerecord id into a URL-safe GUID.

In my attempts to use the three of these together, I found that the sortable_element format regex, which is used to extract the id from the id attribute of the li tag, was not acceptable for use with the GUID plugin. At first glance, it looks like it should have worked. Anyway, by trying to follow the documentation, I tried the following:

The document said the format was a regex, so I gave it a regex. This did not work! It creates invalid javascript.

<%= sortable_element('tasks', :url => {:action => 'update_positions'}, 
                              :ghosting => true,
                              :format => /^task_(.*)$/,
                              :only => 'task')%>

Ok so I regex does not work, I will try a string.

<%= sortable_element('tasks', :url => {:action => 'update_positions'}, 
                              :ghosting => true,
                              :format => "^task_(.*)$",
                              :only => 'task')%>

String does not work, so let’s try a javascript string.

<%= sortable_element('tasks', :url => {:action => 'update_positions'}, 
                              :ghosting => true,
                              :format => "'^task_(.*)$'",
                              :only => 'task')%>

As you can see my approach to problem solving is not methodical. It is more brute force.

The moral of the story is to use a javascript string for the format configuration for the sortable_element.

rails.vim

Wednesday, January 23rd, 2008

I have to admit that I was lured to the TextMate on Mac OS X for my rails development. I got into it. In fact, I required that Andy use it (and buy it) as well on a project that we were working on together. Since that time I have discovered rails.vim, which was developed by Tim Pope. I do not know Tim, but I have to give him Kudos for a job well done. There is still a lot to learn. If you are a vim user, then you need to check out his other plugins. I am about to do that. The reason that I am writing this post now is because Tim has created a website that is dedicated to rails.vim. I just thought everyone should know.

Let me know if you want to try this plugin or anything else with vim, and I would be glad to give you a hand.

Update: I just remembered that I wanted to make a point about rails.vim. It works on every platform that you can run vim on. If you switch platforms like the weather changes (as I do), then this would be something worth adding to your virtual toolbox.

Great News! Rails 2.0 is here.

Friday, December 7th, 2007

I just wanted to announce this just like everyone else.

http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done

Ruby on Rails: the name of the form with form_for

Thursday, October 4th, 2007

Whenever I work with forms in rails, I get so confused. The API documentation is not really clear regarding how to set a name for the form. There are other places that I get confused, but I will solve one problem at a time. The form_tag takes three arguments.

  1. The first argument is the url or action, and you can use the url_for syntax. This can be a string or a hash.
  2. The html options go into the second argument. This is where I would add a name option. It should be inside a hash.
  3. You can put more options in the third argument. This will be a hash.

This is what you would use for use in rails…

<% form_for ({:action => "update", :id => @user}, {:name => "myForm" }, {}) do { -%>
...
<% end -%>

The output should look like this…

<form name="myForm" action="/account/update/1" method="post">
...
</form>