Monday, January 30, 2017

How to Add Rails 5 project to git Repository

Goals

  • Create a local git repository
  • Add all our files to the git repository
  • In order to publish our application, we need to add our application and any changes we make over time to a "revision control system". In our case we're going to use git because it is (relatively) easy and it is what our app server, Heroku, uses.

Steps

Step 1

Type this in the terminal:
git init
It doesn't look like anything really happened, but git init initialized a new repository in a hidden directory called .git.
You can see this by typing ls -a (lisall files).

Step 2

Type this in the terminal:
git status
git status tells you everything git sees as modified, new, or missing.
You should see a ton of stuff under Untracked files.

Step 3

Type this in the terminal:
git add .
git add . tells git that you want to add the current directory (aka .) and everything under it to the repo.
git add
With Git, there are usually many ways to do very similar things.
  • git add foo.txt adds a file named foo.txt
  • git add . adds all new files and changed files, but keeps files that you've deleted
  • git add -A adds everything, including deletions
"Adding deletions" may sound weird, but if you think of a version control system as keeping track of changes, it might make more sense. Most people use git add . but git add -A can be safer. No matter what, git status is your friend.

Step 4

Type this in the terminal:
git status
Now you should see a bunch of files listed under Changes to be committed.

Step 5

Type this in the terminal:
git commit -m "Added all the things"
git commit tells git to actually do all things you've said you wanted to do.
This is done in two steps so you can group multiple changes together.
-m "Added all the things" is just a shortcut to say what your commit message is. You can skip that part and git will bring up an editor to fill out a more detailed message.

Step 6

Type this in the terminal:
git status
Now you should see something like nothing to commit, working directory clean which means you've committed all of your changes.

Explanation

By checking your application into git now, you're creating a record of your starting point. Whenever you make a change during today's workshop, we'll add it to git before moving on. This way, if anything ever breaks, or you make a change you don't like, you can use git as an all-powerful "undo" technique. But that only works when you remember to commit early and often!

More at http://docs.railsbridge.org/intro-to-rails/add_the_project_to_a_git_repo 

How to set the Default Page in Rails 5

Steps


Step 1: Add a root route

Open the file config/routes.rb in an editor (eg NotePad++)
Look for the line Rails.application.routes.draw at the beginning of the file, and add the line root 'topics#index' after it. When you are done the start of the file should look like this:
Rails.application.routes.draw do
  root 'topics#index'


Step 2: Confirm your changes

Go back to http://localhost:3000/. You should be taken to the topics list automatically.

More at http://docs.railsbridge.org/intro-to-rails/setting_the_default_page 

Sunday, January 29, 2017

Role-based Authorisation in Rails

Simply add access-granted to your Gemfile:
gem 'access-granted', '~> 1.0.0'
then bundle and run the generator to create your starter AccessPolicy:
rails generate access_granted:policy
which you can find in app/policies/access_policy.rb.
Forums are a good showcase of user hierarchy I mentioned above, because they usually need a hierarchical permission system based on the following roles:
  • moderators
  • registered users
  • guests
The order in which roles are sorted is also the order of importance. The moderator is the role with the most permissions and the guest is the role with the least.
In Access Granted roles are defined in the same, top-to-bottom, order:
class AccessPolicy
  include AccessGranted::Policy

  def configure
    role :moderator, proc { |user| user.moderator? } do
      # permissions will go here
    end

    role :member, proc { |user| user.registered? } do
      # permissions will go here
    end

    role :guest do
      # permissions will go here
    end
  end
end
Every role has a name and an optional predicate to check if it’s active for the user.
Note: Above you can see me using .moderator? and .registered? methods inside the Procs - these are app-specific and may come from, for example, ActiveRecord::Enum module.

More at
https://blog.chaps.io/2015/11/13/role-based-authorization-in-rails.html

How to Add a new column to an existing table via db:migrate

Use this command at rails console rails generate migration add_fieldname_to_tablename fieldname:string
and
rake db:migrate to run this migration
You can also do
rake db:rollback
if you have not added any data to the tables.Then edit the migration file by adding the email column to it and then call
rake db:migrate
This will work if you have rails 3.1 onwards installed in your system.
Much simpler way of doing it is change let the change in migration file be as it is. use
$rake db:migrate:redo.
This will roll back the last migration and migrate it again.

Saturday, January 28, 2017

How to create a Rails Project with SQL Server Adapter

gem install rails -v 4.2.7.1
rails _4.2.7.1_ new MYAPP --database=sqlserver

Database.yml

adapter: sqlserver mode: dblib host: 127.0.0.1 port: "1433" username: sa password: Password1337 database: test timeout: 20


SQL Server Rails Database.Yml

The corresponding /config/database.yml file should be as follows
development:
  adapter: sqlserver
  host: 127.0.0.1 # used when dataserver is blank
  port: 1433
  database: database_name
  username: sa
  password: billgates
Note: you are supposed to create the database in SQL Server

Friday, January 27, 2017

How to use Active_Scaffold with Rails (Updated 19th Feb 2017)

To get started with a new Rails project
Added to Gemfile
gem 'active_scaffold'
gem 'active_scaffold', github: 'activescaffold/active_scaffold', branch: 'master' 
Run the following commands
bundle install
rails g active_scaffold:install
bundle exec rake db:create
rails g active_scaffold:resource User name:string
bundle exec rake db:migrate
Nb. In Rails5, you can use rails db:create and db:migrate 

Run the app and visit localhost:3000/users

See also https://vhochstein.wordpress.com/2010/08/28/setup-activescaffold-rails-3/

and http://vinsol.com/blog/2010/04/09/introduction-to-active-scaffold-part-i/

How to run Rails in terminal mode ?

C:\RailsProjects\pms4mysql>rails s
=> Booting Puma
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.6.2 (ruby 2.2.6-p396), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

Which Version of Ruby and Rails ?

I still have a CRM application running 24 x7 x 365 since 2007 using Ruby 1.86 and Rails 1.25 combination running on a Windows 2003 Server :-) I then used the Aptana IDE for which development was discontinued a few years ago.

Going back to Rails, I discovered RubyMine 2016.3 and is using it with RailsInstaller Windows Ruby 2.2 distribution.

Packages included are



Wednesday, January 18, 2017

active_scaffold 3.4.38

gem 'active_scaffold', github: 'activescaffold/active_scaffold', branch: 'master'

VERSIONS:

  1. 3.4.41.1 - September 30, 2016 (267 KB)
  2. 3.4.41 - September 29, 2016 (267 KB)
  3. 3.4.40 - September 26, 2016 (267 KB)
  4. 3.4.39 - July 19, 2016 (267 KB)
  5. 3.4.38 - May 27, 2016 (267 KB)
Show all versions (107 total)

RUNTIME DEPENDENCIES (1):

DEVELOPMENT DEPENDENCIES (3):

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42