Thoughts, information and reflections about technology


Ruby on Rails Tips including general tips and specific coding methods.


Rails- How to tell the type of a column.

I was working with a Rails app that pulled data from a non rails database.

Things were a bit quirky and I wanted to double check the type of the column. I found that putting the following in a view will work.

<%= opportunity.column_for_attribute(‘yearly_sales’).type %> 

In this case, it returned “decimal”. 

Use Rake Notes instead of Git Grep to get a list of notes in your rails project

When you create a Rails project, it is helpful to put notes in the project. The notes can look like the following in your controllers:

# TODO change the alignment of the column

    # FIXME – User password retrieval is not working as expected
# OPTIMIZE Add indexes

Or, in the case of views, use the following format Continue reading

A quick way to have a link_to show as a button instead of a text link

link_to can be modified to show a button instead of a text link. The trick is to enclose the link/button text in a button tag and add .html_safe .

<%= link_to ““.html_safe, ‘’, target:’_blank’, class: ‘button’%>


<%= link_to "< button>My Blog< /button>".html_safe, '', target:'_blank', class: 'button'%>

Continue reading

Ruby – Form tag must be outside any table elements.

If you are using form tags in a ruby view, they need to be outside of any table elements or the form/submit button will not work properly.

The following will work:

<%= form_tag documents_path, :method => ‘get’ do %>

            <%= text_field_tag :search, params[:search] %>             <%= submit_tag “Search”, :name => nil %>

<% end %>

Continue reading

Use whoami to check before running bundle install so you don’t run it as root

I screwed up my droplet (ruby on rails) on my digitalocean hosting by running bundle install as root. When you do that, there is a warning that this will break rails for other users. I haven’t taken the time to figure out how to fix that. Since I was getting started with that hosting, I decided to simply delete the existing droplet and recreate it.

However, since I do need to use root from time to time, I made it a standard procedure to always run whoami before running any bundle commands. That way, I can make sure I am logged in as rails and not root.

site monitoring with Ruby on Rails

I needed a way to show the status (Up/down) of internal Ruby applications.  I found an answer on StackOverflow that pointed me in the right direction (Apologies that I can’t locate that post). . I modified that somewhat by putting it into a method and passing the site name to it.

If you put the following code in a controller, and all it as indicated in the remarks from your view, it will check the site and respond with UP or down.  I have a list of about a half dozen applications in a table with a status column. Continue reading

Contact me