iphone and gis development notes
By Rupert
By Rupert
Nov 25th
Its been a while I haven’t setup an svn repository for SCM. Anyhow, here are the steps just in case I forget again and again…
1. Add a new trac setting in /etc/apache2/sites-available/default
2. Copy a template
cp -Rf /var/www/trac/trac-template /var/www/localdumplings
3. Restart Apache2
4. Resync the repository
trac-admin localdumpling resync
Nov 20th
1. I was trying to get the http headers dump from a mobile phone. So I quickly dump it in a log file to see its contents..
headers['Content-Type'] = 'text/xml; charset=utf-8' for header in request.env.select {|k,v| k.match("^HTTP.*")} logger.info(header[0].split('_',2)[1] + ":" + header[1]) end
Reference:
http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers
2. However, please note that you can actually see everything from the request as parameters.
Parameters: {“MSAG-ADDRESS-PREFIX”=>”aSTARTa”, “format”=>”xml”, “protocol”=>”ussd”, “user-agent”=>”Jakarta Commons-HttpClient/3.0.1″, “WHOISD-ABONENT”=>”8613520747210″, “action”=>”menu”, “controller”=>”ussd”, “subscriberID”=>”8613520747210″, “WHOISD-USR”=>”-1″, “host”=>”wap.watago.mobi”, “WHOISD-USSD-MESSAGE”=>”", “content-length”=>”0″}
This means we can easily do..
@whoisd_abonent = params['WHOISD-ABONENT'] || nil
Nov 18th
Taken from http://guides.rails.info/testing_rails_applications.html
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:
*The action of the controller you are requesting. This can be in the form of a string or a symbol.
*An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).
*An optional hash of session variables to pass along with the request.
*An optional hash of flash values.
Example: Calling the :show action, passing an id of 12 as the params and setting a user_id of 5 in the session:
get(:show, {'id' => "12"}, {'user_id' => 5})
Nov 18th
If you want user_id to be ‘nil’, then omit it from your fixtures. I tried setting user_id: nil before, and it turned out to be ’0′ in the database.
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html <% u = UserLogin.create( :password => 'foo') %> <% u.password=('password') %> user_no_profile: email: noprofile@yahoo.com admin: false user_id: nil salt: <%= u.salt %> salted_password: <%= u.salted_password %>

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html <% u = UserLogin.create( :password => 'foo') %> <% u.password=('password') %> user_no_profile: email: noprofile@yahoo.com admin: false salt: <%= u.salt %> salted_password: <%= u.salted_password %>

Before pulling your hair out on what went wrong with your functional tests, check the test database if you have the correct values in your records. Remember ’0′ is different from ‘nil’.
Nov 16th
1. will_paginate docs
Main http://github.com/mislav/will_paginate/wikis
Reference http://mislav.uniqpath.com/static/will_paginate/doc/
Clone URL: git://github.com/mislav/will_paginate.git
2. Installation as a gem
http://github.com/mislav/will_paginate/wikis/installation
gem sources -a http://gems.github.com
Once installed, do script/server
3. Controller
class PoiAppController < ApplicationController def poi_by_category mylimit = 100 sql = "SELECT pa.* FROM poi_apps pa WHERE pa.id IN " + "(" + "SELECT pc.poi_app_id " + "FROM poi_categories pc " + "WHERE pc.categ_node_id LIKE '" + params[:node_id] + "%%'" + "LIMIT " + mylimit.to_s + ")" #@poi_apps = PoiApp.find_by_sql(sql) @poi_apps = PoiApp.paginate_by_sql [sql], :page => params[:page], :per_page => 10 end end
4. View
<h2>POIs</h2>
<div clas="page_info">
<%= page_entries_info @poi_apps %>
</div>
<table>
<tr>
<td>POI_APP_ID</td>
<td>CN_NAME</td>
<td>EN_NAME</td>
</tr>
<% for poi in @poi_apps %>
<tr>
<td><%= poi.id %></td>
<td><%= poi.cn_name %></td>
<td><%= poi.en_name %></td>
</tr>
<% end %>
</table>
<%= will_paginate @poi_apps %>5. Checkout the styles http://mislav.uniqpath.com/static/will_paginate/
Comments