Add the following lines of codes in public/.htaccess. Rails won’t handle this folders. RewriteCond %{REQUEST_URI} ^/(folder-name/|images/|stylesheets/|javascripts/).* RewriteRule .* – [L]
Archive for the ‘Ruby on Rails’ Category
Restrict rails from accessing particular folders
Posted in Ruby on Rails on November 27, 2007 | Leave a Comment »
Mailer settings for Rails app
Posted in Ruby on Rails on November 27, 2007 | Leave a Comment »
Add the following lines in your environment.rb and replace the values with your settings. (mail server name, server name, email address, password) config.action_mailer.server_settings= { :address => ‘mail.servername.com’, :port => 25, :domain => ‘servername’, :user_name => ‘email-address-to-authenticate’, :password => ‘password-to-authenticate’, :authentication => :login (or) :authentication => :plain (if you are not providing password to authenticate) }
Cron tab in Media Temple Grid Server
Posted in Ruby on Rails on November 27, 2007 | Leave a Comment »
The following is the way to write cron task in the media temple grid-server. /usr/bin/curl [url] [url] – This URL should point to some controller which does the task for you. (eg.) – /usr/bin/curl http://neilsys.com/cron/invoke_function The time to invoke the cron and other settings can be done using the control-manager in the media temple.
Undefined method `strftime
Posted in Ruby on Rails on November 2, 2007 | 1 Comment »
Use DateTime.parse() to solve this error. Strftime deals with date objects. You may be trying this with String Value.
converting into new TimeZone
Posted in Ruby on Rails on October 20, 2007 | Leave a Comment »
The following code converts the “time” to new “timezone value”. Paste the following code in the application.rb or wherever you like def convert_zone(to_zone) #notify the current timezone original_zone = ENV[”TZ”] #finds UTC time utc_time = dup.gmtime #change the zone into the requested zone(parameter value) ENV[”TZ”] = to_zone #convert the UTC time to local time in [...]
Multiparameter assignment errors
Posted in Ruby on Rails on October 17, 2007 | 1 Comment »
I came across this error when dealing with Date attribute. Rails active record throws this error when you try to assign the “datetime” value to a date attribute. Changing the db field accordingly fixes this error.
connecting multiple databases
Posted in Ruby on Rails on August 16, 2007 | Leave a Comment »
Connecting to multiple databases in web application is not needed mostly. But for larger application , we have to choose this model. This can be done very easily in ROR. This is acheived through the “before_filter” filter. We specify the database configuration in “database.yml”. Normally this has three parts(development,production and test). Here mention the other [...]
Date validation in rails
Posted in Ruby on Rails on August 3, 2007 | Leave a Comment »
You might have noticed that there is no inbuilt-validation for date in Ruby on Rails. I came across this plugin which does date validation. validates_date :dob, :message=> “DOB is an invalid format” Here is the plugin source: http://svn.viney.net.nz/things/rails/plugins/validates_date_time/
Redirect to some page if controller not exists
Posted in Ruby on Rails on July 24, 2007 | Leave a Comment »
If we try to access the controller which doesn’t exist. We end up with an error. This can be solved using the following way. If a controller doesn’t exist in the rails application, the request is redirected to some other page. Add this code in ‘public/routes.rb’ map.connect ‘*path’, :controller => ‘account’, :action => ‘redirect_to_default’ Add [...]
xml processing
Posted in Ruby on Rails on July 20, 2007 | Leave a Comment »
The REXML which is a ruby ‘xml processor’ is useful to parse the XML documents. I have used this processor in my applications. The usage is as follows. you need to include it within your Ruby controller: require “rexml/document” include REXML This includes the REXML library and includes the REXML namespace. Save the following xml [...]