Posted by Jim Morris
Wed, 18 Oct 2006 06:45:47 GMT
I ran into a problem using text_field_with_auto_complete in a view
where I wanted to have many of them created by an iteration. You can
use the :index option for the text_field, but it doesn't carry over to
the various divs used in the AJAX calls.
<% 0.upto(10) do |legi| %>
<% @leg= @mission.legs.find(:first, :conditions => ['legnum = ?', legi]) %>
text_field_with_auto_complete( :leg, :name, {:index => legi, :size => 20})
<% end %>
<% end %>
is what you really want to do, just as for a regular text_field.
I googled around and found this bug
report for a fix to
text_field_with_auto_complete that allows :index, as that fix does not
appear to be in the current stable release of Rails or on Edge rails, I just created a
my_text_field_with_auto_complete and it worked like a charm!!
def my_text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
if(tag_options[:index])
tag_name = "#{object}_#{tag_options[:index]}_#{method}"
else
tag_name = "#{object}_#{method}"
end
(completion_options[:skip_style] ? "" : auto_complete_stylesheet) +
text_field(object, method, tag_options) +
content_tag("div", "", :id => tag_name + "_auto_complete", :class => "auto_complete") +
auto_complete_field(tag_name, { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
end
So I put this in app/helpers/application_helper.rb and simply use
my_text_field_with_auto_complete in my views.
Here is what the controller side looks like...
def auto_complete_for_leg_name
leg= params[:leg].keys[0]
auto_complete_responder_for_name params[:leg][leg][:name]
end
...
private
def auto_complete_responder_for_name(value)
param= value.downcase + '%'
find_options= {
:conditions => [ 'LOWER(lname) LIKE ?', param ],
:order => 'lname ASC',
:limit => 6
}
@names = Person.find(:all, find_options)
render :partial => 'names'
end
Posted in Rails | Tags rails, text_field_with_auto_complete | 18 comments | no trackbacks
Posted by Jim Morris
Sun, 01 Oct 2006 00:20:00 GMT
I use Lugarus excellent Epsilon Editor for most of my
programming editing needs, on Win32 and Linux.
(An exception is for Java programming where I use Eclipse).
I have spent some time writing extensions to Epsilon to handle Ruby
and Rails programming, inspired mostly by Textmate on Mac/OSX, and
Eclipse for Java. I tried using the Eclipse for Ruby, but I was very
disappointed, also the developers have made some design decisions I
can't live with (like no auto indent after opening braces etc).
I have tried Komodo Pro as described
here.
OK the Epsilon editor is not free, it costs about $250 ($99 for an
upgrade) which includes all platforms, and the license lets you use it
on your Laptop and Desktop, in fact you can use any version of Epsilon
on up to four computers you own. The result is a professional, solid,
stable Editor, that is what you get when you pay for something. (This
editor has been around at least 20 years, which is when I started
using it on DOS!). In addition to running as an X Windows program and
a console program on windows and Linux it also runs on Mac OS X,
FreeBSD, OS/2 and DOS.
The Editor is an Emacs clone out of the box, it also has CUA and Brief
emulations (well key bindings). The best feature IMHO is the fact you
get most of the source code for the editor which is written in its own
c-like language called eel. This makes it much easier to write
extensions and customizations for the editor if you are familiar with
C. (I never could wrap my brain around Lisp which is why I don't use
GNU Emacs). It also runs in console mode as well as windows mode,
which is useful if you have to login via ssh etc to edit files.
Seeing how every programmer has their own ideas of what an editor
should do and its look and feel, easy customization is crucial.
The extensions I have written for Epsilon are all freely available, as
are extensions written by other users. (Various language modes,
template extensions, SCM extensions etc).
In the past I wrote a java help extension that tried to do context
sensitive help, this worked OK but not as well as Eclipse.
Recently I wrote a bunch of extensions for Ruby and Rails, thanks to
the ruby mode extension written by Timothy Byrd (available on Lugaru's
download page) I was able to get syntax highlighting and formatting
already done. I added some simple help extensions, a snippet facility
(ala Textmate), and some convenience actions for Rails development. I
also extended Timothy's ruby mode extension with something that
completes the #{} when # is typed in a string. (I first saw this in
Textmate and hated it, but it grew on me, until I had to have it on
Linux). I have avoided the temptation to also do the automatic closing
of { ( " etc that you find in Textmate because I still hate those, but
they are easy to do using the same technique I used for #{}.
I've also added the ability to run the current buffer through the ruby
interpreter and show the results in a pop up window, also to run a
specific unit test if the file is a Ruby test case.
The key strokes any command uses is easily modified, as well as the
colors used for syntax highlighting.
The version of ruby_mode.e on Lugarus site does not currently have the
latest changes I have made, so it can be downloaded from the link below...
The other extensions can also be downloaded from my site...
These can be installed by copying them to your ~/.epsilon folder, and
adding a load line to your einit.ecm file, see the comments in the
source file. The snippets should be un-tarred into the ~/.epsilon
folder. The README explains how to load them.
eg add this to your einit.ecm file:
(load-eel-from-path "ruby_mode.e" 2)
(load-eel-from-path "rubyhelp.e" 2)
(load-eel-from-path "snippets.e" 2)
(load-eel-from-path "rename_in_place.e" 2)
Also here are the color codes I use for ruby_mode, these are designed
by Timothy: (Change the window-black to whatever color set you are using)
&window-black color class for ruby-brace: [0x725CEB on 0x0]
&window-black color class for ruby-class: [0xD9D240 on 0x0]
&window-black color class for ruby-comment: [0xC0C0C0 on 0x0]
&window-black color class for ruby-global: [0xFFB737 on 0x0]
&window-black color class for ruby-keyword: [0xFF8000 on 0x0]
&window-black color class for ruby-number: [0xFF9090 on 0x0]
&window-black color class for ruby-punctuation: yellow on black
&window-black color class for ruby-regexp: [0x007FFF on 0x0]
&window-black color class for ruby-shell-cmd: [0x8FFF2F on 0x0]
&window-black color class for ruby-shell-subst: [0x8FFF8F on 0x0]
&window-black color class for ruby-str-subst: [0xFFC0C8 on 0x0]
&window-black color class for ruby-string: cyan on black
&window-black color class for ruby-perl-var: red on black
Although you can browse for files that epsilon has currently open and
switch between these buffers, the method is fairly crude by todays
standards of tabbed windows etc, so I wrote a little graphical helper
called
project_browser.rb
that uses the fox window toolkit. It just shows a tree of the
directory it was given on the command line, and if you click on any of
the files they open in the epsilon window. This is a lot like the
project browser windows you find in Textmate, Eclipse and others. You
need to install fox version 1.4 and the fox14 gem too to use this. It
also allows you to exclude files and directories from display in the
tree, by putting a YAML file called .proj_exclude.yaml in the
project directory, I'll document this further if there is any interest
in it (Leave a comment if you are interested). It allows multiple
project directories to be open and shows them in tabs at the top. I'm
also working on integrating subversion into it. It could also be
adapted to work with virtually any editor that allows files to be sent
to the editor by a separate process.

Posted in Rails, Ruby, Linux | Tags editor, epsilon, ide, rails, ruby | no comments | no trackbacks
Posted by Jim Morris
Thu, 10 Aug 2006 05:39:00 GMT
I got a license for Komodo Pro,
(Komodo-Professional-3.5.3-262321-linux-libcpp5-x86) and started
trying to use it, I have the latest KUbuntu, with GTK installed so I
had no problems installing Komodo as far as libraries and requirements
were concerned, however running it had me stumped, I ran into
immediate problems (some of my own making I'll admit).
First I saw a stream of errors on the screen, they didn't seem fatal
but are annoying, for instance...
(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_width: assertion `pixbuf != NULL' failed
(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_height: assertion `pixbuf != NULL' failed
(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_rowstride: assertion `pixbuf != NULL' failed
(Gecko:24458): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
(Gecko:24458): Gdk-CRITICAL **: gdk_pixbuf_get_from_drawable: assertion `gdk_window_is_viewable (src)' failed
For a commercial product costing around $299 that seemed a little
unnecessary.
The first problem was my making I launched Komodo from the command
line in the installation directory, then deleted the installation
directory, which caused it to have hysterics about chdir etc, although
to be honest an xwindows IDE probably shouldn't care where it is
launched from, as it would normally be launched from a button or
desktop icon.
Tech support was very fast in responding to my email though, and they
didn't even know I had a pro license. They asked a bunch of questions,
which I answered, but seeing as the remaining problems were non-fatal
I wasn't too concerned about the response, which I haven't got yet,
but I would like to know if all those GTK errors are normal.
The more disturbing problem was when I tried to write a simple Ruby
script, I expected completion as you would see with Java and Eclipse, but
instead typing:
str= ""
str.
gave me an error:
error determining members: don't know how to make a suitable dumb_get_members for Ruby
This error was what I got at first, after going back and typing str.
again I got the expected list of possible completions, seems this
happens the first time every time, either it is slow figuring out what
to complete or it is very buggy. (Update see later, it is the former,
it is slow figuring out what type something is).
Time.
Did give me a list of completions most times. When it does decide to
offer a list of completions, it also shows the parameters for the
calls, like Eclipse/Java does, that's nice, I hope it is reliable
though.
OK got word back from tech support, apparently it can take "a couple
of seconds" for Komodo to catch up with typing, so my example of...
str= ""
str.
Would probably not work unless I waited a few seconds between the two
lines, I think this may be acceptable as it is unlikely to be an issue
in normal use. In practice it seems to be more than a couple of
seconds BTW.
The main reason for me trying Komodo was for the code completion,
without intelligent code completions I really don't see the use for an
IDE, I can use my trusty Epsilon editor from
Lugaru, with the ruby syntax highlighting and
formatting extensions
and my own contribution to the Epsilon library
snippets, much
like the great Textmate snippets (although not nearly as complete),
there are also various user contributed extensions for various source
code code control systems etc here.
Yes Epsilon is quite expensive for an editor, but I have been using it
for nearly 20 years, upgrading every few years or so, it is basically
Emacs with a c-like extension language (instead of lisp), it is very
solid, and runs on all the platforms I use (Mac OS/X, Windows and of
course Linux). It does not have code completion of course (although I think
I can write an extension ala Vim7 to do that, watch this space).
Maybe I should mention what I am looking for in an IDE for Ruby and
Rails...
I want:
- syntax highlighting
- auto indentation
- auto-correction (or at least error highlighting, or suggestions)
- snippets (or templates)
- code completion (showing the possible methods for a variable called
intellisense or intelligent code completion by some)
- word completion based on something in the source already, or
from a tags list or from a known-word list
- showing the parameters for a given method I am currently
typing
- full debugging (with breakpoints, watches, stepping and
variable examination)
- SCCM integration (subversion, CVS, perforce)
Basically everything I get when I use Eclipse and Java.
I get some of this with Epsilon, and Textmate but they are not IDEs so
do not have debugging or code completion, or error detection.
Back to Komodo...
It has Perforce, CVS and Subversion bindings built-in, and does show
the files status in the project view.
The auto-indent works nicely, unlike RadRails which I tried but just
didn't get along with as I kind of expect it to be as good as Java and
Eclipse, but my main complaint is it doesn't even auto-indent. (I think
intentionally).
The syntax highlighting in Komodo is OK but not great, I think that
can be tweaked, but I haven't looked that closely.
The debugging does seem to work well, you can set breakpoints, and
step over, into and watch variables, everything you would expect. This
may be worth the price of admission (YMMV).
It does show you highlighting when it detects errors as you type,
within the limitation of Ruby syntax.
The Snippets implementation is pathetic compared to Textmate or
Eclipse, you can't specify tab stops, you can't type the trigger word
for a snippet and have it expanded on TAB, you have to either bind it
to a key sequence, or double click the snippet name in the toolbox,
that is simply clunky, and pretty much unusable. There are *NO*
built-in snippets, you have to create them all yourself, so if you like
typing "for" then tab and have a for loop created forget it, unless you
create it yourself then you have to find the "for" snippet in the
toolbox and double click it. I also couldn't find any on the web, I
think for the price of this product they should supply most of the
expected snippets. The other thing I don't like is the snippets will
pop up a dialog box asking for input, instead of the usual way of
just highlighting the text and typing over it to replace it.
My initial impressions is the editor part is clunky, given the
excellent examples of Eclipse and Textmate, it simply doesn't compare
as far as modern editing conveniences such as snippets are concerned.
The debugging seems capable, and probably the best I have seen for
Ruby.
The code completion is slow and doesn't always work.
The source code control seems a little buggy in some places, although
only from a UI standpoint. (Pops up strange dialog boxes on updates
saying files need to be added, when they don't).
A serious bug is if the file changes on disk, (like if you do a
revert), you get a dialog popping up saying the file has changed on
disk, but you can't get it to go away, clicking OK just pops it up
again, ad infinitum, you need to kill the program to move on.
All in all I think this would be a nice IDE if it were free, and the
personal version may well be useful for some if you want decent
debugging, but I simply can't see a justification for $299 for the
pro-version. (At least not for this version). There is an alpha for
the next version that claims to support Rails development, if they
also fix the snippets and the code completion (which they have not in
the current alpha), then we may be getting close to value for the
money, but right now I think they have a long long way to go before
this product justifies the price tag, and comes close to competing
with the few other editors out there let alone IDEs.
Update
Tech support have been very responsive, and they came up with a macro
that inserts snippets almost the way I expect,
komodo.view.setFocus();
try {
komodo.editor.vCHomeExtend();
var snippet = komodo.interpolate('%s');
var tmpl = komodo.findPart("snippet", snippet, "container");
if(tmpl) {
Snippet_insert(tmpl);
} else {
var msg = "no snippet found named " + snippet;
StatusBar_AddMessage(msg,"debugger",5000,true);
}
} catch(e) {
alert(e);
}
Add this as a macro, bind it to a key (say ALT-=), and then add your
snippets to the same folder as the macro is in, name them
appropriately, and the type im the name hit ALT-= and the snippiet is
found and inserted, pretty neat.
Disclaimer: These are my personal opinions, I am not affiliated with
any editor or IDE manufacturers.
Posted in Rails, Ruby | Tags editors, epsilon, ide, komodo, rails, ruby | 1 comment | no trackbacks
Posted by Jim Morris
Sat, 27 May 2006 00:08:00 GMT
UPDATE 2006-12-06 I have replaced this with a full blown SCM module that works much better, see this posting
It seems that many people are in the same position as I was, they want
to deploy to a remote server farm that does not have access to the
SCCM (subversion,CVS,perforce etc), which is usually behind a corporate firewall.
The following recipe overcomes this by checking out the source code
from the local repository (using svn in this case) and goes into your
deploy.rb.
What it does is checkout the latest copy of the application from your
local subversion repository, tars it up, and copies the tar file to
the remote server, then detars it and does the normal deploy tasks
from then on.
desc <<DESC
Update all servers with the latest release of the source code.
This is a modified version that copies a local copy to the remote site
DESC
task :update_code, :roles => [:app, :db, :web] do
on_rollback { delete release_path, :recursive => true }
#puts "doing my update_code"
temp_dest= "tmp_code"
#puts "...get a local copy of the code into #{temp_dest} from local svn"
# but this could also just be your local development folder
system("svn export -q #{configuration.repository} #{temp_dest}")
#puts "...tar the folder"
# you could exclude files here that you don't want on your production server
system("tar -C #{temp_dest} -c -z -f code_update.tar.gz .")
#puts "...Sending tar file to remote server"
put(File.read("code_update.tar.gz"), "code_update.tar.gz")
#puts "...detar code on server"
run <<-CMD
mkdir -p #{release_path} &&
tar -C #{release_path} -x -z -f code_update.tar.gz &&
rm -rf code_update.tar.gz &&
rm -rf #{release_path}/log #{release_path}/public/system &&
ln -nfs #{shared_path}/log #{release_path}/log &&
ln -nfs #{shared_path}/system #{release_path}/public/system
CMD
#puts "...cleanup"
system("rm -rf #{temp_dest} code_update.tar.gz")
end
This recipe does what many people need todo which is replace the database.yml with the production version, and also repalces the .htaccess with the production version (YMMV)
desc "fix up database and .htaccess"
task :after_update_code do
run "cp #{release_path}/config/database.yml.templ #{release_path}/config/database.yml"
run "cp #{release_path}/public/dot.htaccess.deploy #{release_path}/public/.htaccess"
end
Posted in Rails, Ruby | Tags capistrano, deployment, rails, ruby | no comments | no trackbacks