Archive for the ‘Ruby on Rails’ Category

Ruby on Rails Testing – login gotcha

The Ruby on Rails web application I’m finishing has an administrator interface that allows an admin to manage users, generate reports, etc. Some of these admin functions (like the reports) are not controlled by the admin controller. Of course, to actually test any of the controllers I need to be logged in as [...]

Read the rest of this entry »

Ruby on Rails Code Coverage

I realized that I would need to track my progress over time and began looking for a code coverage tool for Ruby on Rails. It did not take me long to find the coverage tool. However, coverage states that they are not making any changes and that rcov is better. I checked [...]

Read the rest of this entry »

Ruby on Rails Testing – flash.now gotcha

I finished the test for my models and it went pretty well. Today I started on the controller tests. Shortly after starting I ran into some curious Ruby on Rails behavior. I expected that the value of the flash variable would hold a certain value on an unsuccessful login attempt, but instead [...]

Read the rest of this entry »

Dissecting a Regular Expression

I am a beginner at regular expressions, but recently found the need to create one. My goal was to take in a file name, split it at the dot (’.’) just before the file extension and then hash everything to the left to get a unique name to store on the server.
I thought I [...]

Read the rest of this entry »

Render Partial for Email Template

As I create more automated email responses for my system, I realized I should follow the DRY (Don’t Repeat Yourself) principle. So I started down a path to create a separate file containing a header and footer for my emails. At least that part I could rip out, right? Well…not exactly.
Turns out [...]

Read the rest of this entry »

Rails Sweetness

I was recently adding addresses to my site data. For example, a user may have a home address and/or work address, whereas a business may have a physical address and/or mailing address. I wanted to have a single database table that held the information about an address since that seems pretty standard. [...]

Read the rest of this entry »

Thumbnails with RMagick

I continue to prototype my site in order to have something to show potential investors. Recently, I tackled uploading images into a user’s gallery. The ability to upload images was pretty straightforward. You create a form that has a file_field element. For example, you may have something like this:
<%= form_tag({:action => [...]

Read the rest of this entry »

Rails link_to and HTML options

Just a small thing, but I needed to know how to do this and it took me a while to find. Hopefully this will help someone else out.
In HTML, we might declare a link like so
<a title=”Example” href=”/controller/action”>Click Here!</a>
Now, in Ruby on Rails, we want to declare a link, so we use the built [...]

Read the rest of this entry »

Self-Referential, Many-to-Many Relationships

Wow, that title is a mouthful! Yet, it refers to a concept that I explored today in my Ruby on Rails studies.
So, just a quick background on the topic. A self-referential relationship refers to a relationship between a class and itself. For example, every social networking website has the concept of a [...]

Read the rest of this entry »

Salted Hash Login Generator

The remainder of the day, I worked with Ruby on Rails – I am a n00b, so be kind. I am currently looking at the requirements for login and registration. I rolled my own login and registration that was pretty simple using SHA1 encryption for the password, but it was extremely simplistic. So what other [...]

Read the rest of this entry »