Ruby in Controllers vs. Ruby in HTML screens in Rails

Today, I think I finally figured out why I was having so much trouble trying to use my routes, controllers, and views properly, according to REST principals.

The mistakes I had most frequently committed were to use skull tags around variables which were already inside of skull tag statements and to use string interpolation when writing these variables in the controllers. These prevented the program from properly displaying things on the .show pages of some of my recent rails apps and they prevented the methods and routes from properly redirecting my pages.

Instead of using something like:

def create
contact =
first_name: params[:first_name],
last_name: params[:last_name],
phone_number: params[:phone_number]
flash[:success] = “Contact Created Successfully!!”
redirect_to “/contacts/#{}”

I had mistakenly written my redirect lines similar to the following:

redirect_to “/contacts/<%= %>

This was preventing the correct views from loading. Now I understand that the skull tags should be used in the HTML view files only as the Controller methods are already written in Ruby.