Wednesday, January 20, 2016
Tuesday, January 19, 2016
Rails 4 Migrations
http://stackoverflow.com/questions/22815009/add-a-reference-column-migration-in-rails-4
When you already have a users and uploads table and wish to add new relationship between them.
All you need to do is, just generate a migration using following command:rails g migration AddUserToUploads user:references
which will create a migration file as:
class AddUserToUploads < ActiveRecord::Migration
def change
add_reference :uploads, :user, index: true
end
end
Then run the migration using rake db:migrate. This migration will take care of adding a new column named user_id to uploads table (referencing id column in users table) PLUS it will also add an index on the new column.
Then run the migration using rake db:migrate. This migration will take care of adding a new column named user_id to uploads table (referencing id column in users table) PLUS it will also add an index on the new column.
Sunday, January 17, 2016
CSS was not working on Heroku
Add CSS to Heroku
To load the css and assets I ran:
$ bundle exec rake assets:precompile
That still didn't work so I ran:
$ RAILS_ENV=production bundle exec rake assets:precompile
The response:
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = (gave me a long number)
It is still not working 12-19-2015 on Linux but it works on Mac
(skeleton works on both)
Tuesday, January 5, 2016
Installing Postgres on Ubuntu
Heroku uses Postgres for their database so it is quite nice to use it as the database for your Rails app. That way there is a seamless transition.
Postgres Command Cheat sheet
This site is helpful if you are a Mac user and can $ `brew install`:
http://www.jackiejohnston.us/blog/setting-up-user-authentication-with-devise/
https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql
http://postgresapp.com/documentation/configuration-ruby.html
I decided to install Postgres it my Ubuntu ThinkPad.
How To Install and Use PostgreSQL on Ubuntu 14.04 https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04
Digital Ocean has great documentation.
How To Setup Ruby on Rails with Postgres https://www.digitalocean.com/community/tutorials/how-to-setup-ruby-on-rails-with-postgres
Postgres Command Cheat sheet
This site is helpful if you are a Mac user and can $ `brew install`:
http://www.jackiejohnston.us/blog/setting-up-user-authentication-with-devise/
https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql
http://postgresapp.com/documentation/configuration-ruby.html
I decided to install Postgres it my Ubuntu ThinkPad.
How To Install and Use PostgreSQL on Ubuntu 14.04 https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04
Digital Ocean has great documentation.
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
How To Setup Ruby on Rails with Postgres https://www.digitalocean.com/community/tutorials/how-to-setup-ruby-on-rails-with-postgres
Wednesday, September 23, 2015
haiku - add users endpoints
create, index, show, update, using json_api_org serializers, with request specs
An endpoint is simply a route defined by your rails application. In terms of an API hitting that endpoint will serve up a resource from your application, or perform some form of action. An example may explain this better.
Say we have an application that handles users and we want our API to expose the users resource. If we follow RESTful convention for our API we will expose seven distinct 'endpoints' linked to seven distinct 'actions' (index, show, create, update, destroy, new, edit) surrounding users.
When building our API, we would make is so anyone who visits "www.myapp.com/users" via a get request is returned some data representation of all users in our application. "/users" is the endpoint. Likewise performing a post action to "/users" with valid data is how we create new users. "/users" is still the endpoint but under different context. If you wanted data for just a single user, it may look something like "www.myapp.com/users/1" in which case "/users/1" is the endpoint.
Request specs provide a thin wrapper around Rails' integration tests, and are designed to drive behavior through the full stack, including routing (provided by Rails) and without stubbing (that's up to you).
Request specs are marked by :type => :request or if you have set
config.infer_spec_type_from_file_location! by placing them in spec/requests.
With request specs, you can:
- specify a single request
- specify multiple requests across multiple controllers
- specify multiple requests across multiple sessions
Check the rails documentation on integration tests for more information.
RSpec provides two matchers that delegate to Rails assertions:
ruby render_template # delegates to assert_template
redirect_to # delegates to assert_redirected_to
redirect_to # delegates to assert_redirected_to
JSONAPI::Serializers is a simple library for serializing Ruby objects and their relationships into the JSON:API format.
Wednesday, January 14, 2015
git
$ git commit -m "commit_message"
Yes I know you can do commit messages right in the command line but I like to be more specific about them.
So I just type in:
$ git commit
and a text editor pops up for the commit.
I like to un-comment the files being added, changed and deleted. I also like to write a good description. Unless I am in a hurry or feeling particularly lazy this is how I do it.
I think it is the version of Ubuntu I am using or some other reason I am unsure of but when I go to commit my projects to git and pop open the window it opens in the nano editor as default.
I don't like it. I prefer vim.
So instead of declaring the change in the terminal every time I go to commit I changed the .git/config file.
I did this through the terminal using the ultimate git guide.
$ git config --global core.editor vim
Tuesday, December 9, 2014
YAML
Research & Examples
Yet Another Markup Language
The YAML Cookbook
http://www.yaml.org/YAML_for_ruby.html#simple_sequence
http://stackoverflow.com/questions/3877004/how-do-i-parse-a-yaml-file
Yet Another Markup Language
The YAML Cookbook
http://www.yaml.org/YAML_for_ruby.html#simple_sequence
http://stackoverflow.com/questions/3877004/how-do-i-parse-a-yaml-file
require 'yaml'
thing = YAML.load_file('some.yml')
puts thing.inspect
Subscribe to:
Posts (Atom)