Follow Along as I Stumble on the Path to Learning RoR

Posts tagged “create

Checking Field Values When Posting in RSpec Controller

I was having trouble figuring out how to check that field values posted in RSpec Controller specs.  In models, I will usually do something like:

@foo.reload.name.should eq “bar”

However, that doesn’t work in Controller specs – it doesn’t recognize reload.

In that case, all you have to do is:

assigns[:foo].name.should eq “bar”

Advertisements

Setting up an Existing Rails App Locally

I had to download an existing Rails app and set it up.  To set-up a new Rails app, just follow the directions on the RoR site.

(1) download and install railsinstaller (railsinstaller.org)

(2) in the ruby command window, create a new app in the “sites” directory –

rails new appnamehere

(3) set-up git so you could download/upload to github and heroku (for version control).  follow these directions  and then these (ignore the parts about creating a new app and editing it, just need to set-up git).  when you add the remote, just use change the Hello-World to your app’s name

(4) add heroku.  follow these steps, (skip to step 3 since you set up git earlier)

(5) pull the latest version of your code.  In Git Bash go to (“cd …” for moving up in the directory, cd pathname (ie “cd sites/yourappname”) your app’s directory

(6) in git bash run: git pull heroku master git@heroku.com:yourappname.git

(7) go back to ruby command prompt to create db, run – rake db:create (i had an issue with this once, but this solved it)

(8) Create tables using schema – (i had connection issues, but this answer helped me)

rake db:schema:load

(9) run

rake db:migrate

(10) the tables should be set-up and you should be able to run “rails server” (or rails s for short).  when you go to localhost:3000 in your browser, you should see your app

(11) go to http://appservnetwork.com/ to download everything you need to run phpmyadmin, which will allow you to edit and view tables (structure and data).  i was having trouble the more recent versions so i had to use 2.4.9 (version) and that worked (set the host/domain name to localhost).  you’ll need to know what is the database login info for the development environment for the install of appserv (it will ask for it during the mysql install) – look in the sites/youappname/config/database.yml file for this info

(12) after install appserv, i could go to http://localhost/phpmyadmin/ in my browser to see my database and tables

(13) run “bundle install” in ruby command prompt (installs all gems specified in gemfile)