- sudo apt-get install sqlite3
- sudo gem install sqlite3-ruby
- rails my_project
- rake db:create
Notes to self
Thursday, November 20, 2008
Installing sqlite for rails development
Wednesday, November 19, 2008
Duplicating tables and problem with the structure
To duplicate a table:
mysql> CREATE TABLE products SELECT * FROM old_products;
But the problem with above statement is structure of products may not be the same as old_products. Attribute properties are not copied to the new table. For example of you have an auto_increment field named id, the auto_increment property won't be copied to products table. products.id will be a normal integer field with the default value set to 0. It also means the new id field won't be the primary field. Took me 3 hours to figure this out.
So the best way to duplicate a table is:
1. CREATE TABLE products LIKE old_products;
2. INSERT INTO products SELECT * FROM old_products;
mysql> CREATE TABLE products SELECT * FROM old_products;
But the problem with above statement is structure of products may not be the same as old_products. Attribute properties are not copied to the new table. For example of you have an auto_increment field named id, the auto_increment property won't be copied to products table. products.id will be a normal integer field with the default value set to 0. It also means the new id field won't be the primary field. Took me 3 hours to figure this out.
So the best way to duplicate a table is:
1. CREATE TABLE products LIKE old_products;
2. INSERT INTO products SELECT * FROM old_products;
Thursday, October 30, 2008
Common MySQL stuff
To modify an existing column definition:
ALTER TABLE applications modify id INTEGER NOT NULL AUTO_INCREMENT FIRST;
To rename a column:
ALTER TABLE applications CHANGE old_col new_col;
Wednesday, October 15, 2008
Sorting records based on the exact order of passed parameters to finder
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/dde7efa8f8f455e5/e4090afeb6c27608?lnk=gst&q=loveajax#e4090afeb6c27608
In Ruby:
order = [5,2,3]
Project.find(:all, :conditions => ["id IN (?)", order], :order =>
"field(id, #{order.join(",")})")
In MySQL:
SELECT * FROM projects WHERE (projects.`id` IN (1,2,3,5,7,6)) ORDER BY field(id, 5,1,2,3,7,6);
In Ruby:
order = [5,2,3]
Project.find(:all, :conditions => ["id IN (?)", order], :order =>
"field(id, #{order.join(",")})")
In MySQL:
SELECT * FROM projects WHERE (projects.`id` IN (1,2,3,5,7,6)) ORDER BY field(id, 5,1,2,3,7,6);
Wednesday, September 17, 2008
Basic Authentication using Apache and mod_rails
http://code.google.com/p/phusion-passenger/issues/detail?id=94&can=1&q=allow&colspec=ID%20Type%20Status%20Priority%20Milestone%20Stars%20Summary
Copy pasted from the above link:
Copy pasted from the above link:
What steps will reproduce the problem?
1. Add a password file with htpasswd
2.
ServerName caswell-box
DocumentRoot /home/user/app/public
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AuthName "Enter password"
AuthUserFile /etc/apache2/passfile.passwd
AuthType Basic
Require valid-user
3. Attempt to access the app in your web browser, and either enter the
wrong user/pass or hit cancel.
What is the expected output? What do you see instead?
The expected output is an authentication rejection, instead while the
static assets handled by Apache are restricted, the rails app is run by
passenger and generates pages without CSS/images.
What version of the product are you using? On what operating system?
Ubuntu 8.04, Passenger 1.9.1 RC2
Please provide any additional information below.
Looks like Passenger does not inherit the permissions from apache.
Monday, September 15, 2008
Thursday, September 11, 2008
Subscribe to:
Comments (Atom)