After calling jQuery.noConflict(), you can still use jQuery “$” functionality, but you have to call it using “jQuery(’foo’)” instead of “$(’foo’)”.
Now that jQuery and prototype can coexists peacefully, how does ThickBox work? Well… out of the box it doesn’t. ThickBox uses the “$” syntax, but expects to use jQuery’s implementation of it. So to get ThickBox to work, you need to replace all instances of “$” with “jQuery” in thickbox.js. Now ThickBox should be using jQuery exclusively, jQuery and prototype won’t conflict over “$”, and everything should work fine and dandy. Note: I’ve only tried this using ThickBox 2.1.1, jQuery 1.1.1, and prototype 1.5.0, but it should work on the latest and greatest versions.
Jun
8
2007
Let’s say you have a web app that takes input from the user. How about a phone book app for storing phone numbers. And let’s assume that each person in your phone book can have an unlimited number of phone numbers. In the interface you allow the user to fill in as many phone numbers as they’d like by dynamically creating more and more input=’text’ elements. When the user saves, the data that gets posted to the server looks something like:
/phonebook/save?number=5203842233&number=6029130923&number=9283125248
Basically there are multiple parameters that have the same name with different values. Now in Java to get the values of the numbers you would do something like…
request.getParameterList('number');
…to get an Array of Strings, each element containing one of the numbers (NOTE: my Java is rusty and this could be wrong). In rails there is no such getParameterList method. As I currently understand it, rails only sees the first number. So it thinks that number=5203842233 was the only value passed to the server, the other values are ignored. Looking at rail’s logs confirms this:
Parameters: {"controller"=>"phonebook", "action"=>"save", "number"=>"5203842233"}
So how do you get multiple values with the same name out of the request? You add ‘[]‘ to the parameter name (ie <input type=”text” name=”number[]“/>):
/phonebook/save?number[]=5203842233&number[]=6029130923&number[]=9283125248
Now looking at the log file:
Parameters: {"controller"=>"phonebook", "action"=>"save", "number"=>["5203842233","6029130923","9283125248"]}
When retrieving params[:number], you’ll end up with an Array of the numbers instead of just the first.
no comments | posted in rails
Jun
7
2007
This is useful if you want to log the ip address of the person using your rails app (except when the person is behind a proxy, thanks James!):
request.env['REMOTE_ADDR']
Taken from this ruby thread.
3 comments | posted in rails, ruby
Oct
26
2006
The second Desert Code Camp is coming up this weekend.
“Code Camp is a free, one-day event put on by the local Phoenix community to help promote software development in general. There is no right or wrong language, platform, or technology. If a topic relates in any way to the code that causes a machine to produce a desired result, it’s welcome here.”
The previous code camp was ok, but the sessions were too jammed together. There was no time to meet people and just talk. Everyone kept running from session to session trying to keep up. Some of the sessions were good, while others were a waste of my time.
I’ll be attending again, hopefully they’ve tweaked the schedule enough so it’s no so jam-packed. There aren’t any sessions that are must-attends for me, so I’ll mostly be there to hang out and support the community. If nothing else, at least it’s a free lunch.
Edit: Apparently lunch isn’t free.
no comments | posted in geek community, rails, ruby
Jun
28
2006
The designer of a project I’m working on decided to use the
RedCloth ruby gem in the project we’re working on. He installed the gem on his local machine and added “require ‘RedCloth’” to environment.rb. Now, since he installed a gem and ruby gems by default are stored in the ruby installation directory, the source repository did not contain the RedCloth library.
Unforunately I forgot to get the RedCloth gem. So when I updated my project source from SVN the project broke output in development.log. I eventually figured out that I was missing the gem. So I downloaded the gem, then moved the whole RedCloth folder into the vendor/plugins directory of the rails project.
The lack of error messages pointing me to the “require ‘RedCloth’” was annoying to say the least. Maybe the require statement should be moved someplace else? Someplace after the logger has been initialized maybe? I wonder if other error/issues in enviroment.rb will make WEBrick die out too. Maybe you can start WEBrick with some advanced debugging for these kinds of situations? Hmm, I guess I should do a little research…
2 comments | posted in rails, ruby