June 15th, 2009 by Surendra Singhi
We have been using Exception Notification in many of our Rails Project. After upgrading to Rails 2.3 and using our own version of optimized session class, we have noticed that the error emails generated by this plugin were not sending session information. To fix this the below patch can be used.
-
Index: vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml
-
===================================================================
-
— vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml
-
+++ vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml (working copy)
-
@@ -1,2 +1,2 @@
-
-*session id: <%= @request.session.instance_variable_get(:@session_id).inspect %>
-
-*data: <%= PP.pp(@request.session.instance_variable_get(:@data), "").gsub(/\n/, "\n ").strip %>
-
+*session id: <%= @request.session_options[:id].inspect %>
-
+*data: <%= @request.session.to_hash.inspect.to_s.gsub(/\n/, "\n ").strip %>
Tags: exception_notification, patch, plugin, session
Posted in rails | No Comments »
June 12th, 2009 by skarmakar
Initially when we started kreeti.com was a web service allowing users to share or browse through jokes, humorous articles, or any fun text. We then decided to reshape ourselves and so have moved everything to a new domain and relaunched the website as fstation.net. Check it out, and let us know how you like it. Enjoy!
Tags: fStation, humor, jokes
Posted in Uncategorized | No Comments »
January 30th, 2009 by sdhar
It is very easy to build a local copy of rails documentation and guides. Open terminal and type these commands.
-
$ cd /tmp
-
$ rails doc
-
$ cd doc
-
$ rake rails:freeze:gems
-
$ rake doc:rails
-
$ rake doc:guides
-
$ sudo mv doc /opt/rails-doc
After completing these steps open browser and type
-
file:///opt/rails-doc/api/index.html //api.
-
file:///opt/rails-doc/guides/index.html // guide related to rails development.
Tags: documentation
Posted in rails | 1 Comment »
January 24th, 2009 by Surendra Singhi
When working on a large Rails project, it can be a kludge having the mailers present among the views and other model files. A nice technique to clean up things is to put all the mailers and associated views in the same folder. If you don’t know about this technique then go read it first, and then come back here.
The benefit of having the ApplicationMailer is that you can define the host for the mailers, include ActionController::UrlWriter, other setup methods in a single file and have all the mailers inherit them.
The patch written for action mailer to not use layouts for text/plain email was causing problem with exception notification plugin, so I have modified it slightly so that it checks whether the file parameter passed to it responds to content_type or not.
-
def candidate_for_layout?(options)
-
(!options[:file] || !options[:file].respond_to?(:content_type) ||
-
options[:file].content_type != ‘text/plain’) &&
-
!@template.send(:_exempt_from_layout?, default_template_name)
-
end
Further to clean things up this patch can be moved to ApplicationMailer to ensure that it is only applied for all our mailers and not for other mailers which may be used elsewhere.
Tags: action mailer, folder organization, mailers
Posted in rails | 1 Comment »
January 23rd, 2009 by Surendra Singhi
Here are few simple and easy steps which you can take to ensure your website is search engine friendly.
- Make sure that your page urls are descriptive. For example look at the post urls of this page. They are of the form http://blog.kreeti.com/seo/simple-search-engine-optimization-steps. This is very easy to do in rails. Add the following code to the models:
-
def to_param
-
"#{id}-#{name.gsub(/[^a-z0-9]+/i, ‘-’)}"
-
end
and then while linking to posts, use code like
and not
-
user_path(@user.id) # do not use this
- Ensure that your pages have a meaningful page title, meta description and meta keywords. Title and description should be preferably unique for each page, and relevant to the page. One simple strategy which you can follow to do this in rails is, in the layout file add the following code:
-
<title><%= @page_title || "Default page title" %></title>
and similarly for meta description and keywords.
Then in your actions you can override the default values
-
@page_title = "New title"
-
@page_description = "new description"
-
@meta_keywords = "keyword1,keyword2,.."
- Make sure that all links to meaningless and duplicate pages have rel=”nofollow”. For example, pagination links, links which just sort the page content in a different order, etc., all should have rel=”nofollow” for them. This will ensure that the search engines, when propagating the authority of your page to other linked pages, doesn’t waste them on useless pages, or duplicate links.
- When multiple items on a page are linking to the same page, make sure that all the links with irrelevant terms have rel=”nofollow”, only the links with terms which aptly describe the page shouldn’t have rel=”nofollow”.
- Duplicate versions of your page, say with a different sort order, example a link like /users/recipes?order=created_at, should have
-
<meta name="robots" content="noindex, noarchive" />
in their head element.
- Your stylesheets, javascript files, images used for styling purposes, non-important pages like sign in, join, privacy policy, terms, should all not be indexed. To ensure this, create a robots.txt file like the following
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
User-Agent: *
Disallow: /account
Disallow: /session
Disallow: /images/
Disallow: /stylesheets/
Disallow: /javascripts/
Disallow: /flash/
Disallow: /opensearch.xml
Disallow: /404.html
Disallow: /500.html
Allow: /
Sign up for Google Webmaster and Yahoo Site Explorer, and add your sites to them, and authenticate that your are the owner of it. Both tools provide very valuable information in optimizing a site for search engines.
Tags: html, ruby, seo
Posted in seo | No Comments »
January 1st, 2009 by Surendra Singhi
In Rails 2.2.2 the send! method from ActiveSupport has been removed,this broke the exception notification plugin. So, get the latest release from the github.
Also, the introduction of database connection pools breaks the spawn plugin. So, switch to the latest release of that as well.
Tags: exception notification, plugins, rails, spawn
Posted in rails | No Comments »
December 27th, 2008 by Surendra Singhi
On our rails 1.2.* project we were using enhanced migrations plugin. Recently we decided to make a switch to rails 2.2.* and wanted to use default UTC based migrations versioning which is a part of the rails core now.
Enhanced migrations plugin uses the table migrations_info to store the migrations information but rails 2.2 uses the table schema_migrations by default. When one does rake db:migrate, the rails code checks whether the schema_migrations table exists or not, if the table is not there, then it is created, and if the schema_info table is present, then this table is populated with all migrations upto the version in the schema_info table. But, since we were using the enhanced migrations plugin, the table schema_info was present but wasn’t being used.
So, to make the switch to rails 2.2.* timestamped migrations before doing regular rake db:migrate the following sql code had to be run, to ensure that schema_migrations table is pre-created, and has the correct list of all migrations which have been run.
create table schema_migrations (version varchar(255) not null primary key);
INSERT INTO schema_migrations select id from migrations_info;
drop table if exists schema_info;
Tags: migrations, rails, timestamped
Posted in rails | No Comments »
December 23rd, 2008 by Surendra Singhi
Update: The code given below here causes the exception notification plugin to stop working, get the fixed code from this post. It also contains a better technique to organize the mailers.
Rails 2.2 has added a very cool new feature which allows the use of layouts for mailer-templates, just like the way layouts can be used for views. This is great, but there is one gotcha, when you try sending a multi-part email (both text and html, as you should be), it wraps the mail content with the same layout for both the text/plain version and the text/html version.
After digging around a bit in the ActionMailer code, I came up with the following monkey patch, which will use the layout only for the text/html version of the email. You can put this code in your environment.rb file, it won’t use layout when the mail-template content type is ‘text/plain’.
-
# monkey patch action mailer to not use layouts for text/plain emails
-
module ActionMailer
-
class Base
-
private
-
def candidate_for_layout?(options)
-
(!options[:file] || options[:file].content_type != ‘text/plain’) && !@template.send(:_exempt_from_layout?, default_template_name)
-
end
-
end
-
end
If you can come up with some other better solution than this, then let us know.
Tags: action mailer, emails, rails
Posted in rails | 7 Comments »