Thoughts, information and reflections about technology

Ruby-on-rails

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

 

Tried to use Westhost’s preferred cpanel hosting for Rails — NO GO

Before starting to use any hosting account for a Ruby on Rails project, check the versions they are offering.

I have a number of sites with Westhost. I’ve been with them for a number of years and the service has always been great, even for the cheap hosting plans. However, all of those sites were Joomla except for one WordPress site. Continue reading

Viewing your SQLLite Data (Ruby on Rails beginners)

When people are starting out with Ruby on Rails, one of the key elements is to be able to view the contents of the SQL file. For most people, they will use the SQLLite database. This is a limited implementation of SQL. The tables are all stored in one file which is located in /db of your Rails project.

When you go into production you will almost certainly transition to some version of an SQL server: Microsoft SQL Server, MySQL, Postgres or some other flavor of SQL. These will offer a lot more control as well as multi threading. Continue reading

Capturing failed logins when using adauth

I use the adauth gem to provide authentication through Active Directory for Rails applications. I wanted to give the apps the ability to store failed logins. In other words, if someone tries to log onto an app and their login fails, the IP and login name used will be written to a file.

The first thing I needed was to create a ‘failed_logins’ model with 2 fields: ip and login. The created_at date will log the time the event occurred. Continue reading

Accessing an external sql database from a rails app where the schema prefix differs from the schema prefix used for the app’s tables.

This covers a situation where you need to have rails access an external sql database other than the database used for the application. For example, you might need to pull information from one table to populate fields in your current application.  This is further complicated if your application is using a schema prefix.

1. Set a database connection in config/database.yml. You need to set schema_search_path especially if the external sql table is using a schema prefix other than the schema prefix used by the application. Continue reading

Going back two pages in Ruby on Rails

I had a situation where I had a list of records with edit buttons. After editing a record, the normal course of things is to show the document. The user wanted an easy way to get back to the list.

The list was the result of a combination of searching, sorting and pagination. They would hit the update page, then the show page. This precluded a simple redirect_to :back.

The solution was the following code.

 

<% if session[:administrator] || session[:full] then %>
<%= button_tag “Back to list”, type: ‘button’, onclick: ‘window.history.go(-2)’ %>
<% end %>

Continue reading

Don’t end the name of fields in Ruby with ‘_id’

I was naming a field for a Ruby/Rails project. Since the field referred to an id for something, I named it according.. For example, product_id. That seemed to make sense. 

However, I use a sorting routine to make the column names sortable on a click. 

When I ran it through the sortable routine to make the columns sortable, I got a crash. Continue reading

Contact me
Archives
Categories