Ruby on Rails Tips including general tips and specific coding methods.
I found a tool called brakeman that does vulnerability scans of rails applications. It installs as a gem and you run it from the command line. I had some issues with it using up memory but found a way around it. Continue reading
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
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
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
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 %>
I needed to have a window pop up in a Rails Project without having the header, footer and navigation.
The popup was easy. I created a file called quick_help.html.erb in viewsabout_and_help
I needed to add the following to my routes.rb Continue reading
Form tags in a ruby view need to be outside of any table elements or the form/submit button will not work.
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: Continue reading
I wanted to change the background color of a cell depending on if the contents of and expires field was past or not. This could be useful for dashboard type apps or pages. i.e. red/yellow/green
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