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 %>">
No Comments | April 29, 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)
No Comments | April 25, 2008
Here is a great cheat sheet for all those mysql command line commands in terminal
cheat sheet
No Comments | April 25, 2008
How to remove .svn files
find ./ -name ?.svn? | xargs rm -Rf
No Comments | April 24, 2008
No Comments | April 15, 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
2 Responses | 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
No Comments | April 12, 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%>
No Comments | April 11, 2008
- Install the restful_authentication plugin
- run script/generate authentication user sessions ?include-activation
- rake db:migrate
- see this link
- on the part where you create the mail.rb config/initializer use this link instead, pasting that code in the place of the code recommended by avnetlabs.com?s tutorial
- create a new file called smtp_tls.rb in your lib folder and paste this code into it
- open the production and development configuration files, config/environments/production.rb and config/environments/development.rb and put in the SITE_URL = ?localhost:3000? and for production your webdomain. according to avnetlabs
- edit the user_mailer.rb model to use the SITE_URL variable instead
- Open the email template files (app/views/user_mailer/activation.html.erb and app/views/user_mailer/signup_notification.html.erb) and modify as desired
- that?s it
Resources
1 Comment | April 11, 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:
No Comments | April 10, 2008