Posted by scott
on April 29, 2008
Here?s a great plugin for doing navigation in rails
I didn?t like that too much.
A simpler yet elegant solution is here: simple & elegant
There is also this
And actually, what I usually do is just use the following code and then css it appropriately.
<body id="<%= controller.controller_name %>">
Posted by scott
on April 25, 2008
How to create a symbolic link: ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]
example:
ln -s /usr/local/apache/logs ./logs
or
ln -s #{current_path}/public /home/#{user}/public_html
or
ln -s apps/appname/public /home/username/public_html
or
ln -s ~/forums/vanilla /home/twinsta/public_html/forum
(this last one, make sure to put it in your Capfile in order to keep the forum working when you update your app)
Posted by scott
on April 25, 2008
Here is a great cheat sheet for all those mysql command line commands in terminal
cheat sheet
Posted by scott
on April 24, 2008
How to remove .svn files
find ./ -name ?.svn? | xargs rm -Rf
Posted by scott
on April 12, 2008
Get your git all setup and your project gitified.
Freeze your gems and freeze to edge your project and git push that to the server (rake rails:freeze:gems and rake rails:freeze:edge or rake rails:freeze:edge TAG=rel_2-0-2 see here ) (script/about to see what version your rails is already on. maybe you already froze earlier and forgot)
Capify your project (capify .)
Edit deploy.rb file created by capistrano use this instructions also use hostingrails? wiki for capistrano two Here?s an example of deploy.rb
Edit Capfile created by capistrano example code
Set ENV[?RAILS_ENV?] ||= ?production? in config/environment.rb
Edit .htaccess file to do fcgi instead of normal cgi instructions here
On local machine run cap -T to view commands available
Add an ssh-keygen to the server as well (since it will be taking from github) see here and here
Follow the latter end of these instructions from hostingrails
Posted by scott
on April 12, 2008
It?s a good idea to freeze your project before deploying. To do this run the command: rake rails:freeze:gems
And it?s a good idea to freeze your rails version to by doing: rake rails:freeze:edge
Here?s a tutorial
Posted by scott
on April 11, 2008
To access data that has related data using has_many and belongs_to, first make sure you?ve set up your related ids. For example for the two models posts and attachments, the attachments table should have a field called post_id so that the attachment can be association to the post.
Then make sure you have the appropriate has_many and belongs_to in the models
Then do the following in your view code:
<% @posts.attachments.each do |post| %>
<img src="<%= attachment.public_filename %>" class="attachment" /><br />
<% end%>
Posted by scott
on April 10, 2008
To use the rails find method with conditional dates do the following. inspiration from here
Example:
Record.find :all, :conditions => {:date => 20070400..20070431, :user_id => current_user.id}
Or addition: Record.sum :hours, :conditions => {:date => 20070400..20070431, :user_id => current_user.id}
Now what if you want to use the current month instead of the static typed in months above?
this_month = Date.today.strftime("%Y%m")
start_of_month = this_month + '00'
end_of_month = this_month + '31'
result = Record.sum :hours, :conditions => {:date => start_of_month..end_of_month, :user_id => current_user.id} rescue nil
result = result.round(1) rescue nil
Rails Date method: