Posts Tagged ‘Ruby on Rails’

How to add additional parameters to distinguish Droppables

by Pace on January 3rd, 2008 @ 5:24 pm in Off-Topic
Tags: , , , , , , ,

I’m working on an organizational Ruby on Rails app, code-named “Kyeliblocks”, which is basically a to-do list organized by date. Sort of like a slimmed-down 30 boxes. One of the features of Kyeliblocks is to be able to drag bubbles (to-do items) from one block (calendar day) to another. This was my first time using Rails and script.aculo.us for drag and drop, and I ran into a problem while studying the examples and demos. All the examples, like scriptaculous’s shopping cart demo, had a small fixed number of droppables, so they didn’t need to know which droppable was the target — it was obvious from the action. So I had some code like this to make the bubbles draggable:

<% block.bubbles.each do |bubble| %>
  <div class="bubble" id=<%="bubble_#{bubble.id}"%>>
    ...
  </div>
  <%= draggable_element "bubble_#{bubble.id}", :revert => true %>
<% end %>

and then in the block view, I made the block droppable like so:

<div class="block" id=<%="block_#{block.id}"%>>
  ...
</div>
<%= drop_receiving_element "block_#{block.id}",
  :update => "kyeliblocks",
  :url => { :action => "drag_bubble" },
  :accept => "bubble"
%>

Then in drag_bubble.html.erb, my problem became evident:

I just dragged bubble #<%=params[:id].split("_")[1]%> to some block.

I had just dragged the bubble to some block, but I had no way to know what droppable I had just dragged it to! The draggable id was passed into params as :id, but the droppable id was nowhere to be found. I didn’t want to perpetrate a horrible hack like using 14 different copy-and-pasted action names for each of the 14 blocks visible on the page at any given time — the action name was the only way I could see to differentiate the target droppable.

But I was just being completely dense. That’s what every parameter other than :action is for, in the :url hash. All I needed to do was this:

<div class="block" id=<%="block_#{block.id}"%>>
  ...
</div>
<%= drop_receiving_element "block_#{block.id}",
  :update => "kyeliblocks",
  :url => { :action => "drag_bubble", :block_id => block.id },
  :accept => "bubble"
%>

(note the :block_id parameter on the :url line), and then my drag_bubble.html.erb had all the information it needed, right there in the params hash!

I just dragged bubble #<%=params[:id].split("_")[1]%>
to block #<%=params[:block_id]%>.

Now of course this was just an intermediate step for debugging — I want the action to actually do something instead of just render a template. But I still wanted to share my embarrassingly simple solution with y’all, in case some other Rails noob can save themselves a couple of hours of hair pulling. (:

I am so not cut out to be a sysadmin.

by Pace on November 25th, 2007 @ 9:12 pm in Off-Topic
Tags: , , , , , ,

Yay! I got my shiny new Rimuhosting VPS. They had pre-installed some packages at my request, like Ruby, Rails, emacs, and Postgres. My first order of business was to get my Ruby on Rails test application moved over from my Windows laptop to my shiny new Rimu Linux server. First step, create a user account. Whoa, I have no idea what I’m doing. I google some basic sysadmin tutorial stuff and learn how to tweak the /etc/passwd file. I try that, but then I don’t know the password to use when I try to log in as myself. FAILED.

Eventually I discover the useradd script, which lets me set an initial password for the new user. SUCCESS.

I zip the directory tree and upload it to usualerror.com (just for temporary storage). I try to use scp to download it. It just hangs. FAILED.

I try ftp. Command not found (!). FAILED.

I think, “Aha, I can just use lynx to navigate to the page and download it that way!” Command not found. FAILED.

I try to figure out how to download ftp. I had thought it would be standard in any Linux distro, but apparently lots of things I expected to be installed weren’t installed. But I can’t think of any way to download things without using scp, ftp, or lynx. FAILED.

Eventually I dig around hard enough to stumble upon sftp. ftp isn’t installed, but sftp is. So I try that but it hangs just like scp. Google tells me that Lunarpages (where usualerror.com is hosted) doesn’t work with sftp. FAILED.

Finally I find lftp. I think I found it by doing rpm -qa. Sigh. All this pain caused by one missing l. lftp has some small amount of success — I can connect to usualerror.com and navigate the directory tree, but as soon as I try to do an ls or download a file, it hangs. FAILED.

Luckily, I remember a similar problem I had about 6 years ago. It had something to do with passive mode. I dig around and find that you can turn off passive mode in lftp by the “set ftp:passive-mode false” command. I do that and download the file! SUCCESS.

The file was zipped on Windows, but I decided to be optimistic and try to unzip it on Linux. And to my astonishment, it worked! SUCCESS.

Next, to start up a MySQL server. (I’m planning on ditching MySQL as soon as possible, I was just using it for testing.) Where is MySQL? It’s not in /usr/local/bin. It’s not in /opt/local anywhere. It’s not in anywhere I’m familiar with on a Linux system. I dig around for about a half hour and still can’t find it. FAILED.

Eventually, I think by interminable googling, I find it in /usr/libexec. I had never even seen that directory before. I start it up. But I can’t do anything because the permissions on some directory are set wrong. FAILED.

I figure out what directory is flummoxed and set the permissions. SUCCESS.

I start up my Rails app and it works perfectly fine! SUCCESS!

I had a similar debacle trying to figure out where to put the ruby-mode files for emacs. Fortunately, by this time I had figured out to just use find . | grep emacs, so that saved some time.

And after that began the PostgreSQL wrangling. After 3 hours, I finally got postgres to work on its own, but Rails still can’t hook up to it. It keeps giving me the error message FATAL C28000 Mno PostgreSQL user name specified in startup packet Fpostmaster.c L1540 RProcessStartupPacket. Sigh. I am so not cut out to be a sysadmin. Debugging code is so much more fun than debugging installation issues.

rimuhosting

by Pace on November 13th, 2007 @ 7:51 pm in Off-Topic
Tags: , , ,

I’ve decided to go with Rimu to host my upcoming Ruby on Rails application application. (That is, the web application to handle job applications.) They seem very knowledgeable, very dedicated to customer support, and they provide root access on a VPS. I was worried about becoming a full-time sysadmin/babysitter of the RoR app, but they sent me the following email that clinched it for me. And I also learned something about Ruby on Rails uptime, admin, and deployment that I hadn’t been able to get a straight answer to until now.

About keeping your rails app up, rails is usually stable enough on most modern deployments to not need too much babysitting. But we can help you set things up such that your mongrel processes and other stuff get restarted, just in case they crash.

For the quick and routine stuff, we usually do the admin free of charge. But if things do get hairy, we charge $10/15 mins. And we tell you if something will be charged before we do it, so you won’t get unexpected charges.

When you get your hosting with us, you get really good support. All our support people are real linux engineers. We’re not call center people. We are knowledgeable about things and some of us are even rails developers. So if you ever get yourself into a tight spot, we will be able to help you.

When you’re ready to order your VPS, just head on to this page:

http://rimuhosting.com/order/startorder1.jsp?type=18

Just mention that you want the rimu rails stack to be installed. Also mention any other special requests you may have or what other specific apps you want installed. If you have other questions, just email us.

Sincerely,
Sim

Ruby on Rails vs. Django

by Pace on October 26th, 2007 @ 8:56 am in Off-Topic
Tags: , , , , , , ,

I’m about to start writing a web front end to a PostgreSQL back end. After looking at oodles of choices (Nenest, OpenToro, Alpha Five, php, JSP, cocoon, Plone, etc.) I’ve narrowed it down to either Ruby on Rails or Django. Ruby on Rails has more hype, but Django also sounds really good, and I’ve heard good things about Python. I don’t know either Python or Ruby yet; I know Lisp, Java, and a smattering of Perl. I’ll post again with more details about my decision process and my perceived pros and cons of each, but first I want to get some input without biasing y’all. Does anyone have any experience with Ruby on Rails or Django? How about Ruby or Python? Any input would be much appreciated; I’m planning on making this decision by Tuesday.