Also if you have 2-3 or more apps running in production then managing such exception mails is also a big headache. In such case one have to keep track of many things like which type of error is resolved/unresolved for which project etc… .
So, here is a good news for those who don’t know about Hoptoad. It is an hosted service by thoughtbot which receives your exceptions, notify you once per error type by email and keep track(resolved/unresolved, count etc…) of your errors on project basis.
By now its a free service. I’m gonna use this as my next project goes live. What abt you??? ;-P
]]>First of all create a rails app and install tinyMCE rails plugin:
1) rails tinymce
2) script/plugin install git://github.com/kete/tiny_mce.git
3) rake tiny_mce:scripts:install
We will be using aspell utility to check spellings so install “aspell” first. You can do it by “apt-get install aspell” or “port install aspell”
Once it is done then add following two lines in your layout(application.html.erb):
1) <%= javascript_include_tiny_mce_if_used %>
2) <%= tiny_mce if using_tiny_mce? %>
Now consider that I have a Users controller and User model with a text field ‘about_me’, and I want to use tinymce with spellchecker for that field.
To convert about_me textarea(new user form) to tinyMCE, add following code to users controller:
**Please cross check that you have added(enabled) ’spellchecker’ in :plugins and added spellchecker button(I have added it in :theme_advanced_buttons2).
Now if you go to new user form you will see that about_me text area is replaced by tinymce editor with spellchecker button.
Now, add two more lines for spellchecker in above tinymce editor configuration:
1) :spellchecker_languages => “+English=en” (english language)
2) :spellchecker_rpc_url => “/users/spellchecker” (rails url where spellchecking will be done)
So our final configuration will be look like:
Now download Spelling.rb, save it as spelling.rb in your rails lib dir and change ASPELL_PATH at line 7 according to your aspell installation.
Once it is done include this module(”include Spelling”) in application.rb or you controlller (here in our case users controller).
Now, create an action in named spellchecker in you controller(’users’):
Now, Type some thing in tinymce editor and click on spellchecker button. It will highlight misspelled words.
And when you click on highlighted misspelled word it will show suggessions.
Enjoy
]]>But, for SEO sake I had to change configuration so that wordpress can be access by http://domain.com/blog instead of http://blog.domain.com/
The problem was if I configure wordpress for http://domain.com/blog and go to this url, the request was handled by rails app because of domain.com virtualhost.
So what I did? I changed apache virtualhost configuration for http://blog.domain.com and http://domain.com as:
Also I created a symbolic link to wordpress installation directory under rails public folder(ln -s /var/www/html/wordpress /var/www/html/railsapp/public/blog).
Now remember to change your wordpress address and blog address options to http://domain.com/blog under settings tab of wp-admin section.(Thanks Amit for pointing this out)
I restarted apache and it worked fine. Wordpress was running at http://domain.com/blog and rails app was as http://domain.com/.
]]>I faced this situation many times and found a solution some where on net. I don’t remember the link but it worked.
According to that, you just need to add:
require ‘resolv-replace’
as the first require in /usr/bin/gem file.
enjoy!!
]]>Now if you wish to index the title of associated article with comment for searching, you just need to add ” is_indexed :fields => :body, :include => [{ :association_name => ‘article’, :field => ‘title’, :as=> ‘article_title’}] ”
So, your comment model will look like:
Setup ultrasphinx by issuing:
Now at rails console try:
Simple, we have article and comment models with has_many belongs_to associations. Comments are indexed with their associated article title. So it can return comments if query matches with article’s titles.
Now, consider a case when we wish to change comment model to make it polymorphic. In that case our models will be look like:
Check at rails if associations are working fine:
Now, the point is to index article title with comments. Here we can get associated article using ‘commentable’ i.e. comment.commentable.
So, change ultrasphinx is_indexed code in comment model accordingly:
Note that we have changed associan_name to ‘commentable’.
Next, when we reconfigure ultrasphinx using ” rake ultrasphinx:bootstrap”(since we have changed db schema), it starts throwing errors:
After spending some time on research, I was able to make it work by making some changes in comment model:
Lets check it on rails console:
In such cases we need to define class_name and association_sql in is_indexed statement instead of association_name.
Hope it helps…
]]>For those who are new to Ultrasphinx: Ultrasphinx is a rails plugin and client to the Sphinx(full text search engine) written by Evan Weaver. More about Ultrasphinx here.
Lets get into the situation. Consider a STI case where we are using ultrasphinx to index several fields:
Now assume we have following data in posts table:
and now in application root:
By this point we have created sphinx configuration file, indexed all records from ultrasphinx models and started sphinx search daemon.
Now open script/console and create and fire a query to find some articles:
Here when you run the query you get an exception, because it is trying to find an article with id 5, which actually a story type not article. So why it is trying to find such article?
Now have a look into config/ultrasphinx/development.conf file. Under section “source articles_main” you’ll get “SELECT (posts.id * 3 + 0) AS id, ‘’ AS article_title, posts.body AS body, ‘Article’ AS class, 0 AS class_id, posts.title AS title FROM posts WHERE posts.id >= $start AND posts.id <= $end GROUP BY posts.id" Which is a SQL to get record to index.
If you check it carefully you'll findout that it should select all articles record to index but unfortunately it is selecting all records from table and considering them as articles. To fix it you need to modify this query and add "posts.type = 'Article'" in where condition. So the query should be "SELECT (posts.id * 3 + 0) AS id, '' AS article_title, posts.body AS body, 'Article' AS class, 0 AS class_id, posts.title AS title FROM posts WHERE (posts.type = 'Article') and posts.id >= $start AND posts.id <= $end GROUP BY posts.id"
But still there is a problem. If you do this manually you have to do it again and again whenever you issue "rake ultrasphinx:configure" because this configuration file will be overwritten.
Better option is to add conditions in models as is_indexed options like:
and it worked fine.
Manik gave me an idea to write a patch for ultrasphinx to add such conditions automatically in case of STI. So may be another post related to ultrasphinx will be soon ;-)
Update: Here is the patch Git patch: Fix STI Issue. After applying this patch you need not to add conditions explicitly for such case. It will automatically check and add conditions for STI.
]]>1) Trailing whitespace
2) Indent SP followed by a TAB
3) Unresolved merge conflict
The first error “Trailing whitespace” is because of carriage-return/line-feed(windows style line feed/end). To resolve this problem comment following lines(58-60) in .git/hooks/pre-commit file:
The second one “Indent SP followed by a TAB” is because of leading spaces/tabs. To resolve this problem comment following lines(61-63) in .git/hooks/pre-commit file:
The third one “Unresolved merge conflict” is because of seven or more successive occurrence of = or < or > characters. Major chances of having seven = character in README or doc files. To resolve this problem replace following line(64) in .git/hooks/pre-commit file:
by
These tricks worked for me, I hope it could help you.
]]>svn patch to add schema info to spec file and spec fixture file
git patch to add schema info to spec file and spec fixture file
I gave an introductory presentation in VinSol. I am sharing it with you, this is not very explanatory as I focused on speech more. Please share your views.
For example, lets assume that we need to add a column ‘role’ in users table(User model). In this case generate a migration like:
Output:
Here AddRoleToUser plays the main role. ‘Add’ specifies the we want to add column(s) and ‘User’ separated by ‘To’ specifies the table.
Similarly, if we need to remove a column ‘role’ :
Output:
Here RemoveRoleFromUser plays the main role. ‘Remove’ specifies the we want to remove column(s) and ‘User’ separated by ‘From’ specifies the table.
Isn’t it cool?
]]>And then I started writing my own ruby script for same purpose but with some addition and modification. Commit Notification Script is that script, you can download and configure it with your SVN post commit hook as follows.
Add following line at the bottom of your post-commit file:
* Please remember to change the path of you commit-email ruby script.
Now open commit-email ruby file and modify the following section according to your requirement:
You are done with that, now onwards whenever someone commits the code, you’ll get the commit notification mail like:
]]>I personally didn’t like some sessions. There were people from some company and after every 2 mins they were saying “we are the best”. I think this should not happen in barcamp. As far as I know about barcamp, it is for sharing your experiences, talking about new technology, but not for promoting your company.
I think that, at BarCamp there should be sessions on new things, not on the things that are popular and have similar other services.
There was a very good session by Jinesh Varia on Amazon Cloud Computing. He included Amazon’s simple storage system, and Amazon’s cloud computing(Ec2) in his presentation. He also helped me in answering people while the demo. He gave me a hint that very soon there will a news from Amazon that will surprise us.
I have uploaded my presentation slides on Slideshare.net:
Thanks to Impetus Noida for Hosting Barcamp for second time and Opera for Beer.
]]>If you are planning to Attend/Present something you or want to help us in any way please visit http://barcamp.org/BarCampDelhi3 and add you name in appropriate section.
So see you in the camp ;-)
]]>The other API site which is only focused on Rails is http://www.railsbrain.com/. I like this most. You can also download this API. It is AJAX based fast, useful.
]]>