tag:blogger.com,1999:blog-39289346946846819742024-03-12T21:50:47.439-07:00jason's rails blogThis is absolutely a private note pad for my use only - it is just a list of things that I took ages to find out OR don't want to forget all in one place for me to refer to later. Anyone who finds it can read it - and thats all. Don't come crying to me about anything in it. I did not write for you or the world.Unknownnoreply@blogger.comBlogger59125tag:blogger.com,1999:blog-3928934694684681974.post-47726748441956831322008-12-03T07:07:00.000-08:002008-12-03T07:08:19.000-08:00Start/Stop Mysql on Leopardsudo /usr/local/mysql/support-files/mysql.server start<br /><br />sudo /usr/local/mysql/support-files/mysql.server stopUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-8707566440674754102008-11-13T13:56:00.000-08:002008-11-13T14:09:24.366-08:00Rspec installation<pre style="font-family: verdana; color: rgb(0, 0, 0);"><span style="font-size:78%;">>sudo gem install ZenTest<br />>sudo gem install rspec-rails<br /><br />in application root:<br />>ruby script/generate rspec<br /><br />autotest (if it hangs use >RSPEC=true autotest)</span><span style="font-size:78%;"><span style="background-color: rgb(255, 255, 102);"><br /><br /></span>rake spec<br />rake spec:app</span><span style="font-size:78%;"><span style="background-color: rgb(255, 255, 102);"><br /></span>rake spec:models<br />rake spec:controllers<br />rake spec:views<br />rake spec:helpers<br />rake spec:plugins<br />rake --tasks:plugins<br /><br /></span></pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-9877851735214996662008-11-07T06:22:00.000-08:002008-11-07T06:43:24.241-08:00Compare time<span style="font-size:78%;"><span style="font-family: verdana;">module ApplicationHelper</span><br /><span style="font-family: verdana;">..SOMETIME_FORMAT = "%a %b %d %H:%M:%S %z %Y"</span><br /><span style="font-family: verdana;">..SOMETIME_FORMAT_DB = '%Y-%m-%d %H:%M:%S'</span><br /><br /><span style="font-family: verdana;">..def sometime_this_month(time, format='user')</span><br /><span style="font-family: verdana;">....return time.beginning_of_month.strftime(SOMETIME_FORMAT) if format == 'user'</span><br /><span style="font-family: verdana;">....return time.beginning_of_month.strftime(SOMETIME_FORMAT_DB) if format == 'db'</span><br /><span style="font-family: verdana;">..end</span><br /><span style="font-family: verdana;"> </span><br /><span style="font-family: verdana;">..def sometime_today(time, format='user')</span><br /><span style="font-family: verdana;">....return time.beginning_of_day.strftime(SOMETIME_FORMAT) if format == 'user'</span><br /><span style="font-family: verdana;">....return time.beginning_of_day.strftime(SOMETIME_FORMAT_DB) if format == 'db'</span><br /><span style="font-family: verdana;">..end</span><br /><br /></span><span style="font-size:78%;"><span style="font-family: verdana;">end</span></span><span style="font-size:78%;"><span style="font-family: verdana;"></span></span><span style="font-size:78%;"><br /></span><span style="font-size:78%;"><span style="font-family: verdana;"><br /><br />Time based finds.<br /><br />created_at time from the database is: "2008-10-24 22:06:18 +0200" </span></span><span style="font-size:78%;"><span style="font-family: verdana;"></span></span><span style="font-size:78%;"><br /></span><span style="font-size:78%;"><span style="font-family: verdana;">However retrieving the Time.now results in the format as follows: "Fri Nov 07 15:31:56 +0100 2008"<br /><br />end</span></span><span style="font-size:78%;"><span style="font-family: verdana;"></span></span><span style="font-size:78%;"><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-57425756253844152052008-11-07T06:14:00.000-08:002008-11-07T06:21:32.567-08:00Named scope with variables<span style="font-size:78%;"><span style="font-family: verdana;">in model *.rb (in this case weight_meassurements.rb)<br /><br />named_scope :user_weight_meassurements, lambda { |user_id| { :order => 'created_at DESC', :conditions => ["user_id == ?", user_id] } }<br /><br /></span><span style="font-family: verdana;">named_scope :today, lambda { |today| { :conditions => ["created_at > ?", today] } }</span><br /><br /></span><span style="font-size:78%;"><span style="font-family: verdana;">Calling from the controllers or helpers @user.weight_meassurements.today('2008-11-07 00:00:00') wil retrieve all weight_meassurement record belonging to the user created after midnight of the passed date. <br /><br />You can also call WeightMeassurements.user_weight_meassurements(@user.id) for all this user weight meassurement records. </span></span><span style="font-size:78%;"><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-62398780609947598352008-10-27T22:06:00.000-07:002008-10-27T22:09:58.009-07:00Mysql import<span style="font-size:85%;"><b style="color: black; background-color: rgb(255, 255, 102); font-family: verdana;">mysql</b><span style="font-family:verdana;"> -p -u{Benutzername} {DB-Name} < filename<br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-61779528974808718232008-10-27T02:53:00.000-07:002008-10-27T03:19:01.390-07:00Converting database time to human time<span style="font-family: verdana;font-size:85%;" >model.created_at.begining_of_day.strftime(%B, %Y)<br />>October, 2008<br />model.creted_at.strftime("%d").to_i.ordinalize<br />>25th<br /><br />%a weekday name.<br />%A weekday name (full).<br />%b month name.<br />%B month name (full).<br />%c date and time (locale)<br />%d day of month [01,31].<br />%H hour [00,23].<br />%I hour [01,12].<br />%j day of year [001,366].<br />%m month [01,12].<br />%M minute [00,59].<br />%p AM or PM<br />%S Second [00,61]<br />%U week of year (Sunday)[00,53].<br />w weekday [0(Sunday),6].<br />W week of year (Monday)[00,53].<br />x date (locale).<br />%X time (locale).<br />%y year [00,99].<br />%Y year [2000].<br />%Z timezone name.</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-72115597061514737142008-10-16T03:07:00.000-07:002008-10-16T03:18:31.207-07:00Memcache Rails<span style="font-family: verdana;font-size:85%;" >>sudo port install memcached<br />>/opt/local/bin/memcached -d -m 64 -u www -l <yourip> -p 11211<br /><br />see also<br />/Library/LaunchDaemons/org.macports.memcached.plist<br />memcached -h<br />man memcached<br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-31679230459815942942008-10-13T22:40:00.000-07:002008-10-13T23:48:05.000-07:00Session Cookies and Application Strategy<span style="font-size:85%;"><span style="font-family:verdana;">- <span style="font-weight: bold;">Do you need protection_forgery? Yes!</span><br />- <span style="font-weight: bold;">Does a browser need cookies turned on? Yes!</span><br />- <span style="font-weight: bold;">Is there no otherway around it? No!</span><br />Passing infomation in the url is neiter restful, nor safe!<br />- <span style="font-weight: bold;">What about people that have their cookies turned off? </span><br />We have to give let them know that cookies are safe in the contect of our application, and they hold no personal information and they are encrypted.<br /><span style="font-weight: bold;">- What about mobile phone browsers that mostly have no cookie capabilities?</span><br /><span style="text-decoration: underline;"></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Same as cookies turned off, may adding somthing about mobile phones too.<br />OR<br />The user can set up his account as "Mobile Phone Enabled" from a web browser and tell them about the cookie problem, but give them the solution to have the application use IP as the cooke key - with the small problem that if thier provider issues them with a new IP during the session, they will have to relogin.<br /></span></span><a href="http://dict.leo.org/ende?lp=ende&p=thMx..&search=encrypted"></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-84066276486512400212008-10-13T22:29:00.000-07:002008-10-13T23:43:56.337-07:00Better Cookie Detect<span style="font-size:85%;"><span style="font-family:verdana;">In some cases, you might really really want to know it the visiting browser has thier cookies on or off. One reason that I an think off is that you are using some ajax stuff on your the landing page that lets unregistered users edit a list or somthing.<br /><br />This is a way of doing it.<br /><br />1. Check to see if a cookie has been set for the session,<br />2. if not then check to see if this ip is in the middle of cookie detection<br />3. if not then redirect to a method and check again - if no cookies are on now, then be sure they are off.<br /><br />Now you can either ask them to put them on to gain full functionallity of the application, or let the application blend out functions that cause UPDATE, PUT or DESTROY requests and instead show a flash error message that informs them of the reduced functionality.<br /><br />This means that you will force a redirect on each request for browsers that have thier cookies off.<br /><br />In the application.rb add the following:<br /><br /><span style="font-size:78%;">before_filter :cookies_required, :except => [:check_for_cookies]<br /><br />protected<br /><br />def cookies_on?<br />..!request.cookies["_yourapp_session"].to_s.blank?<br />end<br /><br />def cookies_required<br />..return unless request.cookies["_yourapp_session"].to_s.blank?<br />..if DetectCookie.find_and_destroy_or_create_by_remote_ip(request.remote_ip, request.request_uri) then return end<br />..session[:return_to] = request.request_uri<br />..redirect_to detect_cookies_path<br />end<br /><br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">>ruby script/generate model DetectCookie remote_ip:string request_uri:string<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">>rake db:migrate<br /><br />Create a controller: dectect_cookies.rb<br />add the following:<br /><br /><span style="font-size:78%;">class DetectCookiesController < ApplicationController<br />..before_filter :cookies_required, :except => :show<br /><br />..def show<br />....if request.cookies["_hausursel_session"].to_s.blank? #change to your cookie session name<br />......detect_cookie=DetectCookie.find_by_remote_ip(request.remote_ip)<br />......detect_cookie ? redirect_to(detect_cookie.request_uri) : redirect_to(cookie_path)<br />....else<br />......redirect_back_or_default(:controller => 'apartments')<br />....end<br />..end<br />end<br /><br /></span><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Add the following to the detect_cokkie.rb file in the models folder:<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;"><br />class DetectCookie < ActiveRecord::Base<br /><br />..def DetectCookie.find_and_destroy_or_create_by_remote_ip(remote_ip, request_uri)<br />....if detect_cookie=DetectCookie.find_by_remote_ip(remote_ip)<br />......DetectCookie.destroy(detect_cookie.id)<br />......true<br />....else<br />......DetectCookie.create(:remote_ip=> remote_ip, :request_uri => request_uri)<br />......false<br />....end<br />..end<br /><br />end</span></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-55060921829215549822008-10-11T14:27:00.000-07:002008-10-13T22:29:33.269-07:00Simple Cookie Detect<span style="font-size:85%;"><span style="font-family:verdana;">All PUT, UPDATE and DESTROY methods require the session cookie with protect_from_forgery or the application will break if a browser has cookies turned off when one of these methods are used.<br /><br />Unfortunately, when a browser calls the application for the first time, the session cookie wil be written, but it wont be read untill the next page request. This makes it impossible to know if cookies are off, or of in the browser so anyone visiting the application first time and lets say, posts a form will be disapointed.<br /><br />This is a simple solution to the problem. All controllers will call a cookies_required method when PUT, UPDATE or DESTROY methods are used. The cookies_required method looks to see it if the session cookie is empty - if it is, it will catch the http-referrer and redirect to the method check_for_cookies - if the session cookie is still empty, then we can be certain that cookies are off in the browser and refrain the user from using the </span></span><span style="font-size:85%;"><span style="font-family:verdana;">PUT, UPDATE or DESTROY methods. Instead we show a message about cookies being off and the application having limited functionality untill they are turned on. </span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><code><br /></code></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Add the following to application.rb </span></span><span style="font-size:85%;"><span style="font-family:verdana;"><code></code></span><br /><span style="font-family:verdana;"><br />..before_filter :cookies_required, :except => [:show, :check_for_cookies]</span><br /><br /><span style="font-family:verdana;">..def check_for_cookies</span><br /><span style="font-family:verdana;">....if request.cookies["_cookie_detect_session"].to_s.blank? </span><br /><span style="font-family:verdana;">......render :text => 'You absolutly Need Cookies on to use this function'</span><br /><span style="font-family:verdana;">....else</span><br /><span style="font-family:verdana;">......redirect_back_or_default(:controller => 'home')</span><br /><span style="font-family:verdana;">....end</span><br /><span style="font-family:verdana;">..end</span><br /><br /><span style="font-family:verdana;">protected</span><br /><br /><span style="font-family:verdana;">..def cookies_required?</span><br /><span style="font-family:verdana;">....return unless request.cookies["_cookie_detect_session"].to_s.blank? </span><br /><span style="font-family:verdana;">....session[:return_to] = request.request_uri</span><br /><span style="font-family:verdana;">....redirect_to(:controller => 'home',:action => 'check_for_cookies')</span><br /><span style="font-family:verdana;">..end</span><br /><br /><span style="font-family:verdana;">..def redirect_back_or_default(default)</span><br /><span style="font-family:verdana;">....session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)</span><br /><span style="font-family:verdana;">....session[:return_to] = nil</span><br /><span style="font-family:verdana;">..end</span><span style="font-family:verdana;"><br /><br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-33618183348096913462008-10-10T10:37:00.000-07:002008-10-10T10:39:06.430-07:00Rails Security<span style="font-size:85%;"><a style="font-family: verdana;" href="http://www.quarkruby.com/2007/9/20/ruby-on-rails-security-guide#csrf">Great security guide</a></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-21450685615148280502008-10-06T05:00:00.000-07:002008-10-06T06:04:13.071-07:00Javascript and RJS<span style="font-size:85%;"><span style="font-family:verdana;">To descide how to handle javascript in ruby you should seperate between.<br /><br />1. Effects (hide, show, highlight, fade ect), and<br />2. Interactive data (with or without visual effects)<br />3. Embedding Javascript the good old way.<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><strong>1. Effects</strong><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Visual effects being anything that just tells the client side javascript engine to do somthing with one or more its DOM's.<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><strong>2. Interactive Data</strong><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Interactive data, would be somthing like a calculating user input and diplaying the resulting sum in realtime.<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><strong>3. Embedding Javascript the good old ways</strong><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;">If you like cluttering every things up javascript, you probably should not being using rails. Apart from needing a lot more programming time, and lines of code and making everything a millon times more dificult to test there is no reason what so ever to fall back to embedding javascript in the views as it used to be.<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">The difference between the 1 and 2 is that in the first case, you don't need to use an RJS file, whereas in the second case you will need and observer and an RJS file to handle the resulting data update when the observer registers user data changes in one or more input fields on a page.<br /><br />Rails Javascript Engine.<br />==============<br />This engine can only do one thing. Wack out javascript to the client side browsers java engine for rendering. The Rails engine has no concept of the state of the page being manipulated by the client side browser java engine.<br /><br />This means conditionals are not directly possible. i.e.<br />if page[:input_field_name] == 'red'<br /> page[</span></span><span style="font-size:85%;"><span style="font-family:verdana;">:input_field_name</span></span><span style="font-size:85%;"><span style="font-family:verdana;">] = 'blue'<br /><br />What you can do is this:<br />page << "if $(('input_field_name').value == 'red' {" # this is a straight javascript string which does not get interpreted page[:input_field_name]=='blue' # this get turned into a java script statement and sent to the client page << "}" </span></span><span style="font-size:85%;"><span style="font-family:verdana;"># this is a straight javascript string which does not get interpreted and finishes the conditional<br /><br />Note the conditional has nothing to do with rails - the engine in the browser interprests the code output by page.</span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span><span style="font-family:verdana;"></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-30153194940124950052008-10-06T04:42:00.000-07:002008-10-06T07:29:30.039-07:00Renanaming URL routes<span style=";font-family:verdana;font-size:85%;" >Renaming the URL'S defaults generated with the controllers.<br /><br />i.e you have a resource you address in your code:<br /><br /><code><% link_to("award", certificate_path(1)%></code><br /><br />This might be because you actually only have one certificate. You have the link on the page showing Awards, but when the user clicks on the link the URL will show:<br /><br />/certificates/show/1<br /><br />To change this you need to edit the routes.rb<br /><br /><code>map.resources :certificates</code><br /><br />to the following:<br /><br /><code>map.the_certificate 'award', :controller => certificates, :action => 'show', id => 1<br />map.resources :certificates</code><br /><br /></span><span style=";font-family:verdana;font-size:85%;" >Now you can change:<br /><br /><code><% link_to("award", certificate_path(1)%> to <% link_to("award", the_certificate_path %></code><br /><br /></span><span style=";font-family:verdana;font-size:85%;" >NOTE 1:<br /><br />doing this does not work properly:<br /></span><span style=";font-family:verdana;font-size:85%;" ><code><br />map.certificate 'award', :controller => certificates, :action => 'show', id => 1<br />map.resources :certificates</code><br /><br />i.e. trying to overwrite mapped resource with the same name to point to the proxy url.<br />It messes up when you render a form with somthing like<br /><% form for @certificate %><br /><br /></span><span style=";font-family:verdana;font-size:85%;" >NOTE:<br /><br />Whenever you make any changes to the routes.rb file you will need to restart your server!!!!<br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-26230394669330928392008-10-06T03:10:00.000-07:002008-10-06T03:42:36.043-07:00Loading Tables with Defauls Application Data in Migrations<span style="font-size:85%;"><span style="font-family: verdana;">1. Rake a migration to make the table</span><br /><span style="font-family: verdana;">2. Make a new directory 'development_data' in app/db/migrate/</span><br /><span style="font-family: verdana;">3. Make a YML file with the "tablename.yml" (check pural!) containing the default data for the table you need for the application (don't mix wiht test data)</span><br /><span style="font-family: verdana;"></span><span style="font-family: verdana;">4. Run rake db:migrate to create the tables and load them with the default data from the YML</span><br /><br /><span style="font-family: verdana;">==== Table Create Migration example</span><br /><br /><span style="font-family: verdana;">> ruby script/generate migration Certificates title:string description:text </span><br /><br /><span style="font-family: verdana;">==== YML example<br /><br /></span><code><br /><span style="font-family: verdana;">certificate:</span><br /><span style="font-family: verdana;">..id: 1</span><br /><span style="font-family: verdana;">..title: "All About This Certificate"</span><br /><span style="font-family: verdana;">..description: "Blah Blah."</span><br /><br /><span style="font-family: verdana;">..id: 2</span><br /><span style="font-family: verdana;">..title: "All About This Certificate"</span><br /><span style="font-family: verdana;">..description: "More Blah Blah."</span><br /><br /></span><span style="font-size:85%;"><span style="font-family: verdana;">==== Create Load Migration example</span><br /> </span><br /><span style="font-size:85%;"><span style="font-family: verdana;">> ruby script/generate migration Certificates title:string description:text </span><br /> </span><br /><span style="font-size:85%;"><span style="font-family: verdana;">==== Load Data example</span><br /><br /></span><span style="font-size:85%;"><span style="font-family: verdana;"><code><br />class LoadCertificatesData <><br /><span style="font-family: verdana;">..def self.up</span><br /><span style="font-family: verdana;">....down</span><br /><span style="font-family: verdana;">....directory=File.join(File.dirname(__FILE__),"development_data")</span><br /><span style="font-family: verdana;">....Fixtures.create_fixtures(directory,"certificates")</span><br /><span style="font-family: verdana;">..end</span><br /><br /><span style="font-family: verdana;">..def self.down</span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;">....Certificate.delete(:all)</span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;">..end</span><br /><span style="font-family: verdana;">end</span><br /></code><br /><br /></span><span style="font-size:85%;"><span style="font-family: verdana;">==== Load Data example</span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;"></span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;"></span></span><span style="font-size:85%;"><span style="font-family: verdana;">This strategy might fail over time if you are adding and deleting existing colums in migrations, so you might have to end up doing all your load migrations after all the structural migrations have finished. </span><br /> </span><span style="font-size:85%;"><span style="font-family: verdana;"></span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;">However, this might fail to if table relations ships are complex - so then you might have to fall back to an administration interface in the application where you build the tables from the YML file with your own programming. </span><br /></span><span style="font-size:85%;"><span style="font-family: verdana;"></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-42562084156084364002008-09-30T06:14:00.000-07:002008-10-13T22:40:39.595-07:00Sessions and, or Cookies<span style=";font-family:verdana;font-size:85%;" >Rails 2.0 + uses a cookie on the client bowser to store session data. Sesion data is used to protect against misuse and data theft.<br /><br />If the client browser has cookies disabled the application with throw an exception for any and all PUT, UPDATE and DESTROY requests.<br /><br />To safeguard this you should diable any code that results in </span><span style=";font-family:verdana;font-size:85%;" >PUT, UPDATE and DESTROY</span><span style=";font-family:verdana;font-size:85%;" > requests if cookies are disabled in the browser client.<br /><br />Just add a protected method in the application controller.<br /><br /><code>helper_method :cookies_on?<br />protected<br /><br />def cookies_on?<br />..request.cookies["_appname_session"].to_s.include?('_appname_session')<br />end </code><br /><br />The "_appname_session" defalts to the name for your application and is defined in the app/config/environment.rb<br /><br /><code>config.action_controller.session = {<br /> :session_key => '_appname_session',<br /> :secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'<br />}</code><br /><br />In your controllers and views you can now write:<br /><br /><code><% if cookies_on? %><br /> <!-- here the code that shows a form sumbit button, for example --> # show the form with the submit button<br /><% else %><br /> <!-- maybe you show a text that tell the user that they cannot use theh form because they have ther cookies deactivated in their browser --> # show the form without the submit button and display a message telling the user that this site protects the identiy of users with coded cookies and they cannot sumbit the form without cookies enabled in the browser.<br /><% end %></code><br /><br />As the session cookie won't be avilable until the user has loaded at least two pages of your application, until then your application will be in a state of "cookies disabled".<br /><br />This is all a bit of a pain, especially in the light of mobile browsers, most of which do not support cookies. However in the light of data protection, there is a real need to come up with practices to deal with this. And rails does a great job - so lets not get pissed off with rails, but more with the twits that seem to think the web is some sort of data free for all.<br /><br />BTW: Setting your own cookie is as easy as<br />cookies [:my_name_of_cookie]="hello this string will now be in a cookie in the users browser"<br /><br />The next time the user views somthing you can read the cookie:<br />value=cookies[:my_name_of_cookie]<br />puts value -> </span><span style=";font-family:verdana;font-size:85%;" >"hello this string will now be in a cookie in the users browser"</span><br /><span style=";font-family:verdana;font-size:85%;" ><br /><span style="font-family:monospace;"></span><code></code></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-16149571108798381102008-09-30T00:01:00.000-07:002008-09-30T00:43:28.203-07:00Rake migrations effecting exisitng tables<span style="font-size:85%;"><span style="font-weight: bold;font-family:verdana;" >Things that can done:</span><br /><span style="font-family:verdana;"><br />Adding a new table, Removing a table, Adding a column to an existing table, Removing a column, Renaming a column, Renaming a table, Adding an index, Adding a primary key.<br /><br />>ruby script/generate migrtion add_price<br /><br />This creates a new migration file in db/migrations<br /><code><br />class AddPrice<br />...def self.up<br />.....add_column :products, :price, decimal, :precision => 8, :scale => 2, :default => 0<br />...end<br /><br />...def self.down<br /> ......remove_column :products, :price<br />...end<br />end<br /></code></span><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-32114861161676507342008-09-20T10:34:00.001-07:002008-09-20T10:38:53.967-07:00error_messages_on<span style="font-size:85%;"><span style="font-family: verdana;">BIG GOTCHA!</span><br /><br /><span style="font-family: verdana;">1. don't use redirect_to in the controller otherwise the view wont get, i.e. display the error message. user ender instead. </span><br /><br /><span style="font-family: verdana;">2. error_messages_on wants the name of the instance variable used in the controller, ie if you use, </span><br /><br /><span style="font-family: verdana;">error_messages_on 'instance_variable'</span><br /><br /><span style="font-family: verdana;">then make sure you use</span><br /><span style="font-family: verdana;">@instance_variable in your controller code. Its this vairable that has the method @instance_vaiable.errors which error_on_messages uses.</span><br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-6431689632987476542008-09-19T00:52:00.000-07:002008-09-19T04:32:26.544-07:00Capistrano Deployment.<span style="font-size:85%;"><span style="font-family:verdana;">Capistrano gets the latest version of the application from a given reposity and puts it online under a specific web domain.<br /><br /><span style="font-weight: bold;">Install Capistrano</span><br />1. install gem >gem install capistrano<br />2. check that worked out >cap -h<br /><br /><span style="font-weight: bold;">Setup app for Capistrano</span><br />1. in root directory of the application>capify<br /><br /><span style="font-weight: bold;">Configure Capistrano</span><br />(don't use cap deploy:cold - which is suposed to workout the configuration - you have to do the following once)<br />1. in app/config - edit the deploy.rb file<br /><br />set :application, "nameofapp"<br /><span style="font-size:78%;">#Note: This will also be the name of the directory created for the app files<br /></span>set :repository, "git@git.whateverthedomainis:whateverthenameis.git<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the location of the repository of the application<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :deploy_to, "/full/path/from/server/root/directory/to/app/directory/on/server/#{application}<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is absolute location on the server where the application root directoy will be placed after being fetched from the repository<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :scm, :git<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the resposity type (in this case a git)<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :scm_user, "name"<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the user_name that is needed to access the repository. note: the need for a password is normally replaced by a ssh public key<br /><br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :user, "name"<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the ssh username for the domain i.e. >ssh username@yourdomain.com<br /><br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :use_sudo, false<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: Capistrano will want to make some directorys on the server, it this is set to true it will use sudo before making them. I suggest to keep this false - capistrano does not need it and less things can go wrong, especially the first time.<br /><br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">set :branch, "whateverbranch"<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: The deal here is that after capistrano has cloned the repository on the server is will checkout this branch. I could not get this to work - and so expect the last version of the master branch to be checked out (at least with git and v2.5 of capistrano)<br /><br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">role :app, "yourdomain" # i.e. www.whatever.com<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the address of the server that hosts the application server (i.e. mongrel, mod_rails etc)<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">role :web, "yourdomain" # i.e. www.whatever.com<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the address of the server that hosts the webserver server (i.e. apache, etc)<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;">role :db, "yourdomain" , :primary => true # i.e. www.whatever.com<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: This is the address of the server that hosts the database (i.e. mysql, postresql)<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: The :primary tells capistrano which server to run any migrations against.<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Setup publickey of your server to access the application repository. </span><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">1. Login to server with a ssh shell session (i.e. >ssh name@dominnameofserver (i.e. ssh me@happy.com)) - If you are not working with public keys, then you should be asked for the password to access - after entering it you should be it.<br /><br />2. cd to home on the server >cd<br /><br />3. cd to the .ssh directory > cd .ssh<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">#Note: check for a file id_rsa.pub if its not there, then run ssh-keygen (just enter return at prompts)<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;">3. enter on command line >more id_rsa.pub<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">4. Copy the key and add it to your existing repository key<br /><span style="font-size:78%;">Note: github.com and assembla.com have a web interface for your to do that if your repository is hosted there.<br /></span> </span></span><span style="font-size:78%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">5. Check that that works by cloning the application repository by hand on the server<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Freeze Rails. </span><br /></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;">>rake rails:freeze:gems<br /></span></span><br /><a href="http://209.85.135.104/search?q=cache:eps1VTQSErQJ:www.akitaonrails.com/2008/5/25/rolling-with-rails-2-1-the-first-full-tutorial-part-1+freeze+rails+2.1&hl=en&ct=clnk&cd=1"><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Vendorize gems #TODO.<br /></span></span></span></a><span style="font-size:85%;"><span style="font-family:verdana;">If you are using gems but cannot install them on a sharehost then you have the option to vendorize them.<br /></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;">>rake gems:install<br />>rake gems:unpack:dependencies<br />>rake gems:build<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Make Spin Script. </span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;">This is a small script in app/script/ called spin.rb<br />This script is called by capistrano after the app has been deployed to start the app and web server<br /><br />#!/bin/sh<br /><br />#{deploy_to}/current/script/process/spawner \<br /> mongrel \<br /> --environment=production \<br /> --instances=1 \<br /> --address=127.0.0.1 \<br /> --port=#{port}<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br />(#TODO Check the above)<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Update Git repository. </span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">git add .<br />git commit -m 'ready to deploy'<br />git push origin master<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Deploy Setup. </span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">git add .<br />git commit -m 'ready to deploy'<br />git push origin master</span></span><span style="font-size:85%;"><span style="font-family:verdana;"></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /><br />cap deploy:setup<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Check Dependencies. </span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">cap deploy:check<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Deploy the Update. </span></span></span><br /> <span style="font-size:85%;"><span style="font-family:verdana;"><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">cap deploy:update<br /></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Server stuff. </span></span></span><br /> <span style="font-size:85%;"><span style="font-family:verdana;">open a shh session on the server<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">>shh name@domin.xx<br />>cd to your app root directy<br />>rake RAILS_ENV=production db:schema:load<br /><span style="font-size:78%;">note: If this does not work - then obviously you will have to find out why and fix it before continuing.<br /></span>>script/console production<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">note: The production environment should load up without any errors.<br /></span></span></span><span style="font-size:85%;"><span style="font-family:verdana;">>>app.get("/")<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">note: This should return a status code of 200, 302 or similar.<br /></span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Deploy Start. </span></span></span><br /> <span style="font-size:85%;"><span style="font-family:verdana;">On the local machine:<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br />>cap deploy:start<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-size:78%;">note: This should return a status code of 200, 302 or similar.<br /></span></span></span><br /><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Now everthing should have fired up and be working. </span></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-23512346110875678382008-09-02T13:08:00.000-07:002008-09-05T08:34:57.406-07:00Developing Rails Plugins with RSpec<span style="font-size:85%;"><span style="font-family:verdana;">To use RSpec while developing plugins install this rspec generator plugin as follows.<br /><br /><span style="font-weight: bold;">Install RSpec Plugin</span></span><br /><span style="font-family:verdana;">script/plugin install git://github.com/pat-maddox/rspec-plugin-generator.git</span><br /><br /><span style="font-family:verdana;"><span style="font-weight: bold;">Create Plugin Framework</span><br />script/generate rspec_plugin new_fu</span><br /><br /><span style="font-family:verdana;"><span style="font-weight: bold;">Setup Autotesting</span><br />create a file: discover.rb to vendor/plugins/new_fu/lib/autotest/</span><br /><br /><span style="font-family:verdana;">insert the following at the top of the discover.rb file:</span><br /><span style="font-family:verdana;"> $:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec]))</span><br /><span style="font-family:verdana;"> Autotest.add_discovery do</span><br /><span style="font-family:verdana;"> rspec</span><br /><span style="font-family:verdana;"> end</span><br /><span style="font-family:verdana;"><br />create a spec.opts file in the plugin/new_fu/spec folder and add the following:</span><br /><span style="font-family:verdana;">--colour</span><br /><span style="font-family:verdana;">--format progress</span><br /><span style="font-family:verdana;">--loadby mtime</span><br /><span style="font-family:verdana;">--reverse</span><br /><br /></span><span style="font-weight: bold;font-size:85%;" ><span style="font-family:verdana;">Set Plugin Location<br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">This avoids naming conflicts with other plugins.<br />create a directory structure within nuw_fu/lib somthing like this.<br />your_name/name_or_your_company<br /><br />Now move the new_fu.rb file into the directory name_of_your_company.<br /><br />Your new_fu.rb file should now be in<br />app/vendors/plugins/new_fu/your_name/name_of_your_company/new_fu.rb<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Start Autotest for Apllication</span><br />Open a terminal window and go to the root of your apllication<br />first type: rake spec<br />It should run through and sync the app with your rspec environment<br />Then type: autotest<br />The autostest should start and re-run everytime you change a file in your application<br /><br /><span style="font-weight: bold;">Set test environment</span><br />open a terminal window - locate the base of your app and type:<br /></span></span><span style="font-size: 85%;"><span style="font-family: verdana;">export RAILS_ENV=test </span></span><span style="font-size:85%;"><span style="font-family:verdana;"><br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Start Autotest for Plugin</span><br />Open a terminal window and go to the root of your plugin directory<br />app/vendor/plugins/new_fu/<br />and type in autotest<br />The autostest should start and re-run everytime you change a file in your plugin<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Set up Plugin init.rb file. </span><br />Locate the init.rb file in vendor/plugins/new_fu<br />add: include 'your_name/name_of_your_company/new_fu'<br /><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;"><span style="font-weight: bold;">Set up Plugin as a module </span><br />Open your plugin file<br />vendor/plugins/new_fu/your_name/name_of_your_company/new_fu.rb<br />add the following.<br /><br />.module YourName<br />....module NameOfYourCompany<br />.......module NewFu<br />.<br />...........def hello_world<br />..............puts "Hello World"<br />...........end<br />.<br />......end<br />...end<br />.end<br /><br />Then in the new_fu_spec.rb file - located in vendor/plugins/new_fu/spec/ - add the following:<br /><br />.require File.dirname(__FILE__) + '/spec_helper'<br />.<br />.describe YourName::NameOfYourCompany::NewFu, "" do<br />......include YourName::NameOfYourCompany::NewFu<br />.<br />......before do<br />......end<br />.<br />......it "should should say hello world" do<br />........hello_world<br />.....end<br />.<br />.end<br /><br />The autotest should have passed on the tests and you should see "hello world" somewhere in the output.<br /><br />######## To Be Continued.....<br /><span style="font-weight: bold;">Further documentation.</span><br /></span></span><span style="font-size:85%;"><span style="font-family:verdana;">Understanding and building plugins - <a href="http://vimeo.com/1412708">Part I</a><br />Understanding and building plugins - <a href="http://vimeo.com/1413035">Part II</a><br />Creating Plugins <a href="http://izumi.plan99.net/manuals/creating_plugins.html">Manual</a><br /><a href="http://izumi.plan99.net/manuals/creating_plugins.html">Autotesting while writing Rails Plugins</a><br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-78324526375502346792008-09-01T07:45:00.000-07:002008-09-01T07:58:47.501-07:00Rspec Helper Extention<span style=";font-family:verdana;font-size:85%;" >Additional Helper Methods (except, with, only) in spec_helper.rb file in project_folder/spec/<br /><br />class Hash<br /><br /> # filter key out of a hash<br /> # {:a=>1, :b=> 2, :c=> 3}.except(:a)<br /> # results of hash after call {:b=> 2, :c=> 3 }<br /><br /> def except(*keys)<br /> self.reject { |k,v| keys.include?(k || k.to_sym) }<br /> end<br /><br /> # override some keys with a new value<br /> # {:a=>1, :b=> 2, :c=> 3}.with(:a => 4)<br /> # results of hash after call {:a => 4, :b=> 2, c: => 3 }<br /> def with(overrides = {})<br /> self.merge overrides<br /> end<br /><br /> # return a hash with only the pairs identified by the +keys+<br /> # { :a=>1, :b=>2, :c=>3}.only(:a)<br /> # results of hash after call {:a=>1}<br /> def only(*keys)<br /> self.reject { |k,v| !keys.include?(k || k.to_sym ) }<br /> end<br /><br />end<br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-25872640443941441102008-08-30T11:27:00.000-07:002008-08-30T11:29:31.386-07:00Setting the Test, Production, Development Environment<span style="font-size:85%;"><span style="font-family: verdana;">>export RAILS_ENV=test </span><br /><span style="font-family: verdana;">>export RAILS_ENV=development</span><br /><span style="font-family: verdana;">>export RAILS_ENV=production</span><br /><br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-38651470232114422132008-08-30T10:11:00.000-07:002008-09-01T07:59:16.750-07:00RSpec CheatSheet<a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://techblog.daveastels.com/2006/09/09/rspec-cheat-sheet/"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_CeoEjIx6WGA/SLmBJxcFf_I/AAAAAAAAAAM/B13ozXkhPtw/s320/rspec+cheatsheet.jpg" alt="" id="BLOGGER_PHOTO_ID_5240361646312226802" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style=";font-family:verdana;font-size:85%;" >>rake -T spec (output of the available rake tasks for rspec)<br />>ruby script/spec -h (output availble plugin rspec options)<br />>ruby script/generate (shows the rspec generators that replace the normal rails generators)<br />(i.e. ruby script/generate rspec_scaffold will show the available options)<br />>rake doc:plugins (generate the rspec documentation in doc/plugins/rspec-rails/index.html)<br />>rake spec (sync the development environement with the test environment before running autotest)<br />>autotest (starts the background testing)<br /><br />IMPORTANT: Set the test rspec it set up to work in the test environment, <a href="http://jasonsrailsblog.blogspot.com/2008/08/setting-test-production-development.html">so make sure it has been set</a><br />Also see extention spec helper methods <a href="http://jasonsrailsblog.blogspot.com/2008/09/rspec-helper-extention.html">post</a><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-30393144611981196562008-08-30T06:35:00.000-07:002008-08-30T10:30:43.781-07:00Git CheatSheet<span style="font-size:85%;"><a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://git.or.cz/gitwiki/GitCheatSheet"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px;" src="http://ktown.kde.org/%7Ezrusin/git/git-cheat-sheet-large.png" alt="" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="font-family:verdana;">.gitignore contains the ignore files (add *.log, .DS_Store, config/database.yml)</span><br /><span style="font-family:verdana;">>git init</span><br /><span style="font-family:verdana;">>git add .</span><br /><span style="font-family:verdana;">>git add "file name"</span><br /><span style="font-family:verdana;">>git status</span><br /><span style="font-family:verdana;">>git --global user.name "name"</span><br /><span style="font-family:verdana;">>git --global user.email "email"</span><br /><span style="font-family:verdana;">>git --global apply.whitespace nowarn</span><br /><span style="font-family:verdana;">>git commit -m "message describing this commit" or git commit -v (shows you the diffs done and lets you write your commit mesage)<br />>git commit -a (commit all files that have been changed)<br />>git commit -a -v (commit all files and show diffs that have been changed)<br /></span><span style="font-family:verdana;">>git log (give ascii log with messages)</span><br /><span style="font-family:verdana;">>git log --stat (ascii output graph of the file changes with + and -)</span><br /><span style="font-family:verdana;">>git log --p (see the diffs of the files)</span><br /><span style="font-family:verdana;">>gitk (launch a visual tool of the git log). >gitk & to run in the background<br />>gitk -all (all local and remote branches)</span><br /><span style="font-family:verdana;">>git branch (show the current branches)</span><br /><span style="font-family:verdana;">>git branch --color (shows local and remote branches in color)</span><br /><span style="font-family:verdana;">>git branch "name of branch" (creates a new branch)</span><br /><span style="font-family:verdana;">>git branch -a (shows all local and remote branches)<br />>git checkout "name of branch" (to work on the named branch)</span><br /><span style="font-family:verdana;">>git rebase "name of another branch" (get current changes from another branch into my working branch)</span><br /><span style="font-family:verdana;">>git diff "branch 1" "branch2" (show the diffs of 2 branches) or pipe to TextMate with git diff "branch1" "branch2" | mate</span><br /><span style="font-family:verdana;">>git merge branch (merges branch into current branch)<br />>git reset --hard ORIG_HEAD (revert the merge)<br />>git stash "message" (save current status of work to a "clipboard")<br />>git stash list (show the contents of the clipboard)<br />>git stash apply (bring the status in the clipboard)<br />>git branch -d branchname (delete a previously merged branch)<br />>git branch -D branchname (delete a non merged branch)<br />>git stash clear (clearsout the stach clipboard)<br /><br /><span style="font-size:130%;">Repositories</span><br />copy project to another machine (cp -r or scp -r)<br />>git clone remotemachineurl (gets a copy of the remote repository from the remote machine)<br />>git fetch (get a copy of all objects from the remote machine - don't merge with local machine)<br />>git pull (syncronizes fetches changes from the remote machine with the local machine with the branch I am currently in)<br />>git push (syncronize local changes back to the remote machine)<br />>git merge (local merging of 2 branches)<br />>git remote show name_of_repository (shows some info on the branches in the remote repository)<br /></span><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-31531024254899867672008-08-30T05:40:00.000-07:002008-09-03T06:29:37.376-07:00Setup New Rails Project<div style="font-family:verdana;"><ol><li><span style="font-size:85%;">Create a new project with: >rails name_of_project, then: >cd name_of_project</span></li><li><span style="font-size:85%;">Optionally if using other database than Sqlite: > rake db:create:all</span></li><li><span style="font-size:85%;">Install RSpec Plugin & Framework. <a href="http://github.com/dchelimsky/rspec-rails/wikis/home">Refer to the latest instructions</a>. </span></li><li><span style="font-size:85%;">Run the RSpec generator to create framework: >ruby script/generate rspec</span></li><li><span style="font-size:85%;">Create latest plugin documents on local drive with: rake doc:plugins. Location of documentation is "name_of_project/doc/plugins/respec-rails/index.html. Open directly in browser with: open -a Firefox doc/plugins/rspec_on_rails/index.html. Or open index.html</span></li><li><span style="font-size:85%;">Install and run RSpec <a href="http://jasonsrailsblog.blogspot.com/2008/09/developing-rails-plugins-with-rspec.html">plugin framework</a> if needed<br /></span></li><li><span style="font-size:85%;">Create the git repository with a cd to the "name_of_project" directory and then: </span></li></ol><div><span style="font-size:85%;"> >git config --global user.name "your name"</span></div><div><span style="font-size:85%;"> >git config --global user.email "your mail@provider"</span></div><div><span style="font-size:85%;"> >git config --global apply.whitespace nowarn</span></div><div><span style="font-size:85%;"><br /></span></div><div><span style="font-size:85%;"> to check the settings see .gitconfig or: >git config --list</span></div><div><span style="font-size:85%;"><br /></span></div><div><span style="font-size:85%;"> >git init (creates local repository and the .git directory)</span></div><div><span style="font-size:85%;"><br /></span></div><span style="font-size:85%;"> create a .gitignore file and add file to ignore </span></div><div style="font-family:verdana;"><span style="font-size:85%;"> *.log</span></div><div style="font-family:verdana;"><span style="font-size:85%;"> database.yml</span></div><div style="font-family:verdana;"><span style="font-size:85%;"> db/schema.*</span></div><div style="font-family:verdana;"><span style="font-size:85%;"> .DS_Store<br /></span></div><div style="font-family:verdana;"><span style="font-size:85%;"><br /></span></div><div style="font-family:verdana;"><span style="font-size:85%;"> >git add . (add all file and contents to firstime checkin)</span></div><div style="font-family:verdana;"><span style="font-size:85%;"> >git commit -m "first commit"</span></div><div style="font-family:verdana;"><span style="font-size:85%;"> >git status (check the repos)<br /><br />see <a href="http://git.or.cz/gitwiki/GitCheatSheet">git cheatsheet</a> for more<br /></span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3928934694684681974.post-87685747471413525782008-08-30T04:19:00.000-07:002008-08-30T06:35:26.227-07:00Setup Rails 2.1 on Mac Leopard<div><span class="Apple-style-span" style="font-family:verdana;"><span class="Apple-style-span" style="font-size:medium;">A version of rails and gem is already installed on the mac so we will update and expand on this installation as follows</span></span></div><div><ol><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" ><span class="Apple-style-span" style=""><span class="Apple-style-span">Get and Install </span></span><a href="http://macromates.com/"><span class="Apple-style-span" style=""><span class="Apple-style-span">TextMate</span></span></a></span><span class="Apple-style-span" style="font-size:85%;"><br /></span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" ><span class="Apple-style-span" style=""><span class="Apple-style-span">Get and Download </span></span><a href="http://www.macports.org/install.php"><span class="Apple-style-span" style=""><span class="Apple-style-span">MacPorts</span></span></a><span class="Apple-style-span" style=""><span class="Apple-style-span"> - Leopard (universal). After the download and installation, edit or add to .bash_profile file the following:</span><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span"> export PATH="/opt/local/bin:/opt/local/sbin:$PATH" (see here for more </span></span><a href="http://209.85.129.104/search?q=cache:1q1SrVOikmIJ:www.buildingwebapps.com/articles/6433-setting-up-rails-on-leopard-mac+rake+create+mac+10.5&hl=de&ct=clnk&cd=6&gl=de"><span class="Apple-style-span" style=""><span class="Apple-style-span">details</span></span></a><span class="Apple-style-span" style=""><span class="Apple-style-span">) </span></span></span></span></span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" ><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span">Update macports from the command line terminal with: >sudo port selfupdate. </span><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span">NOTE: I had a problem with awk not being found during the installation. This was </span></span><a href="http://209.85.135.104/search?q=cache:cdGxkvgtju4J:www.nabble.com/soft-problem-with-awk-td15296232.html+port+install+no+awk&hl=de&ct=clnk&cd=1&gl=de"><span class="Apple-style-span" style=""><span class="Apple-style-span">solved</span></span></a><span class="Apple-style-span" style=""><span class="Apple-style-span"> by running the installation again. </span></span></span></span></span></span></span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" ><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span">Install Git and Svn integration as follows: >sudo port install git-core +doc +svn</span></span></span></span></span></span></span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" ><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span" style=""><span class="Apple-style-span">Update gems with: >sudo gem update</span></span></span></span></span></span></span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" >Install Rspec gem with: > sudo gem install rspec</span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" >Install Zentest with: >sudi gem install ZenTest. You don't need to install the gem if you are only using rails. Zentest enables autotesting in the background.</span></li><li><span class="Apple-style-span" style=";font-family:verdana;font-size:85%;" >Install Rspec <a href="http://github.com/dchelimsky/rspec-tmbundle/wikis">TextMate bundle</a> specifically for rails supporting development: cd to the TextMate Bundles directory, i.e. > cd ~/Library/Appliction\Support/TextMate/Bundles. Then: > git git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle</span></li></ol></div>Unknownnoreply@blogger.com0