Coming from Rails I’d grown quite fond of flash messages. Unfortunately there isn’t a built in way of doing this in MVC4. Luckily, there’s a five minute solution posted on StackOverflow: http://stackoverflow.com/a/11809178/522859
Once implemented, it works just like in Rails:
this.Flash("We need you to login before you can edit anything.", FlashEnum.Warning);
Definitely worth checking out if you’ve got time, even more so if you’ve come over from Rails!
The solution was fairly simple, but adding a few things at once had me looking at it the wrong way. Because I was using the same nested partials for an HTML response as my JSON one, the file extensions weren’t what rails was expecting. To get around this, all I needed to do was fully qualify the partial filenames. For instance:
I was having a bit of trouble with CarrierWave on Amazon S3 today. When attempting to upload files that were larger than ~150kb I received one of the following errors (depending on config):
getaddrinfo: Name or service not known carrierwave
Excon::Errors::SocketError in PhotosController#create
Broken pipe (Errno::EPIPE)
Despite the vague error, the solution was fairly simple. The region configured in my initialiser was different to the one my bucket was created in.
In order to find out which region you need, logon to your AWS console and browse to an uploaded image. Check the endpoint URL (properties > static website hosting) and simply copy the region. For examples:
This is just a quick guide on how to create a test/staging environment with Heroku.
-- Create staging environment
heroku create --remote staging
-- Push to staging app
heroku push staging master
-- Run rake db:migrate on staging app
heroku run rake db:migrate --remote staging
-- Add pgbackups add ons
heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote heroku
-- Create backup of production data
heroku pgbackups:capture --remote heroku
-- Copy to staging environemnt
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote heroku`--remote staging
-- Create a new config file called staging.rb (/config/environments/staging.rb)-- Add environment variables
heroku config:add RACK_EVN=staging RAILS_ENV=staging --remote staging
-- Ready to go !
For those of you using git branches etc, the following may come in handy as well:
-- Create local development branch
git branch development
-- Switch to dev branch
git checkout development
-- Make your changes and commit them
git initgit add .
git commit-m"My changes"-- Push to staging environment (local development branch to staging environment master branch)git push staging development:master
If you run into any trouble, I found the following links pretty helpful: