I did more work with Ruby on Rails and Bootstrap and encountered a few problems that I would like to share on my blog mostly for persons searching for answers.
The glyphicons was not working. I was using the bootstrap-sass gem. Found out that I needed to copy the fonts and link to them in the css file
font-family: ‘Glyphicons Halflings’;
src: url(‘/fonts/glyphicons-halflings-regular.eot?#iefix’) format(’embedded-opentype’),
I copied the font files to /public/fonts otherwise you could place it in /app/assets/fonts/ but you would might have to do some configuration. I am reading that using the asset pipeline is the recommended approach. Also one way to include the glyphicons in the link_to helper is to use the .html_safe function as follows
<%= link_to '<i class="glyphicon glyphicon-user"></i> My Account'.html_safe
I noticed that database tables are automatically created with a primary key id and created_at and updated_at datetimes. So you can chose to not include these when creating your schema. If you need to rebuild your database tables you can use schema:load instead of running all the migrations (there is a note in the schema.rb file that says this is not recommended). The select_collection helper is case sensitive so keep this in mind if it does not work for you. I learnt that I can collapse all folders in the left panel (for me it’s Sublime Text 3 on Windows 10) using alt + click.
I encountered the following error message when trying to change a column type from string to integer
PG::DatatypeMismatch: ERROR: column “column_name” cannot be cast automatically to type integer HINT: Specify a USING expression to perform the conversion.
I found the syntax I needed here but I was getting another error.
PG::UndefinedColumn: ERROR: column “createduserid” does not exist
HINT: Perhaps you meant to reference the column “items.CreatedUserId”.
After doing some troubleshooting I found out that the column name is case sensitive and to maintain the case from the rails code I needed to include the name in quotes as follows
class ChangeCreatedUserIdInItems < ActiveRecord::Migration
change_column :items, :CreatedUserId, ‘integer USING CAST(“CreatedUserId” AS integer)’
This was another error I encountered
PGError: ERROR: column “CreatedUserId” is of type integer but expression is of type character varying at character HINT: You will need to rewrite or cast the expression.
I corrected this by not setting the user id in params but in the model itself as follows
@item = Item.new(params.require(:item).permit(:title, :ItemDetails, :PriorityId, :DateCreated))
@item.CreatedUserId = current_user.id
I found that sometimes if you are not seeing a change reflected in the website immediately try restarting the server. Depends on the type of change and this is not common. Found this nice tool to easily build your datetime format string – strftimer.com. I also needed this html color picker – htmlcolorcodes.com. Also here is a nice list of Bootstrap alternatives.
I had changed the name of the app in Heroku and was getting the following error
C:\Sites\my-tech-demo>heroku git:remote -a my-tech-demo.git
! Couldn’t find that app.
I had to remove the remote link in git and add it back. One way to do this is as follows
git remote rm heroku
git remote add heroku email@example.com:yourappname.git