Skip to content

Instantly share code, notes, and snippets.

@zilkey
Forked from davidott/Terminal commands
Created December 28, 2011 06:23
Show Gist options
  • Save zilkey/1526702 to your computer and use it in GitHub Desktop.
Save zilkey/1526702 to your computer and use it in GitHub Desktop.
Trying to push to git and new controller /views
class SayController < ApplicationController
def hello
@time = Time.now
@files = Dir.glob('*')
end
def goodbye
@time = Time.now
end
def filenames # add the filenames method
@files = Dir.glob('*')
return @files
end
def say_goodnight(name)
Say_goodnight result = 'good night, ' + name
return result
end
#time for bed...
puts say_goodnight('Marry-Ellen')
puts say_goodnight('John-Boy')
end
<p>This file should live in app/views/say/hello.html.erb</p>
<p>
Below is just an example of how you can loop over an array of items. In this case, the array happens to contain a list of filenames
</p>
<ul>
<% for file in @files %>
<li>file name is: <%= file %></li>
<% end %>
</ul>
Sample::Application.routes.draw do
# other routes here....
match 'say/hello' => 'say#hello'
match 'say/goodbye' => 'say#goodbye'
match 'say/say_goodnight' => 'say#goodbye'
end
class SayController < ApplicationController
# localhost:3000/say/hello
# this will render app/views/say/hello.html.erb
def hello
# the following two lines just demonstrate how you can set some variables
# in a controller, and then access those variables from a view.
#
# See the hello.html.erb view for an example of how to use it.
#
# Dir.glob is a quick way to get a list of all file / directory names.
# In this case you are telling it to show all files in the current directory by passing "*"
@time = Time.now
@files = Dir.glob('*')
end
# http://localhost:3000/say/goodbye
# this will render app/views/say/goodbye.html.erb
def goodbye
@time = Time.now
end
# http://localhost:3000/say/say_goodnight
# http://localhost:3000/say/say_goodnight?name=Paul
# this will render app/views/say/say_goodnight.html.erb
def say_goodnight
# Anything in the URL after the ? will be available in `params`
# for example, if you visited http://localhost:3000/say/say_goodnight?name=Paul&age=10 your params would look like this:
#
# {:name => "Paul", :age => "10"}
#
# If you just wanted the "name" that you passed in, you could get that like so:
#
# params[:name]
#
# In the example below, we look to see if a user passed in a name. The || means "or", so the following line says:
#
# If the user passed in a name, use it. Otherwise, set the name to "sir"
#
name = params[:name] || "sir"
# If a user went to http://localhost:3000/say/say_goodnight?name=Paul, the @message would be 'good night, Paul'
#
# If a user went to http://localhost:3000/say/say_goodnight, the @message would be 'good night, sir'
@message = 'good night, ' + name
# In a controller action, in general there's no need to `return` anything.
# Rails will just find the right view template based on the name, and render it
# The view has access to anything that starts with @ - so in this case, the view can use @message
end
end
<p>This file should live in app/views/say/say_goodnight.html.erb.</p>
<p>
To pass a parameter to a controller, you create a form with fields, and the name of each form field gets translated into the name of a param in the controller.
</p>
<p>
For example, in the form below, there is an input with a name of "name". This comes across as params[:name] in the say_controller's say_goodnight method.
</p>
<p>
All of the rails helpers, like "form_for" and "text_field" eventually output HTML forms, like the one below.
</p>
<form action="/say/say_goodnight" method="get">
<label for="name">Who would you like to say good night to?</label>
<input type="text" id="name" name="name" />
<input type="submit" value="Say it" />
</form>
<p>
<%= @message %>
</p>
Davids-MacBook-Pro:blog daviddotterweich$ git.add
-bash: git.add: command not found
Davids-MacBook-Pro:blog daviddotterweich$ git.
-bash: git.: command not found
Davids-MacBook-Pro:blog daviddotterweich$ git. add
-bash: git.: command not found
Davids-MacBook-Pro:blog daviddotterweich$ git
usage: git [--version] [--exec-path[=<path>]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=<path>] [--work-tree=<path>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help <command>' for more information on a specific command.
Davids-MacBook-Pro:blog daviddotterweich$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Davids-MacBook-Pro:blog daviddotterweich$ git add .
Davids-MacBook-Pro:blog daviddotterweich$ git push
Everything up-to-date
Davids-MacBook-Pro:blog daviddotterweich$ git push
Everything up-to-date
Davids-MacBook-Pro:blog daviddotterweich$ git
usage: git [--version] [--exec-path[=<path>]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=<path>] [--work-tree=<path>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help <command>' for more information on a specific command.
Davids-MacBook-Pro:blog daviddotterweich$ git commit
Aborting commit due to empty commit message.
Davids-MacBook-Pro:blog daviddotterweich$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: .DS_Store
# modified: app/.DS_Store
# new file: app/controllers/say_controller.rb
# new file: app/helpers/home_helper.rb
# new file: app/helpers/say_helper.rb
# modified: app/models/post.rb
# modified: app/views/.DS_Store
# modified: app/views/home/home.html.erb
# modified: app/views/posts/_form.html.erb
# new file: app/views/say/filenames.erb
# new file: app/views/say/goodbye.html.erb
# new file: app/views/say/hello.html.erb
# new file: app/views/say/say_goodnight.html.erb
# modified: config/routes.rb
# new file: test/functional/home_controller_test.rb
# new file: test/functional/say_controller_test.rb
#
Davids-MacBook-Pro:blog daviddotterweich$ git commit added new controller and views
error: pathspec 'added' did not match any file(s) known to git.
error: pathspec 'new' did not match any file(s) known to git.
error: pathspec 'controller' did not match any file(s) known to git.
error: pathspec 'and' did not match any file(s) known to git.
error: pathspec 'views' did not match any file(s) known to git.
Davids-MacBook-Pro:blog daviddotterweich$ git commit "added new controller and views"
error: pathspec 'added new controller and views' did not match any file(s) known to git.
Davids-MacBook-Pro:blog daviddotterweich$ git commit 'added new controller and views
> exit
>
Davids-MacBook-Pro:blog daviddotterweich$ git commit 'added new views and controller'
error: pathspec 'added new views and controller' did not match any file(s) known to git.
Davids-MacBook-Pro:blog daviddotterweich$ git commit
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.
Davids-MacBook-Pro:blog daviddotterweich$ git commit -m added new controller and views
error: pathspec 'new' did not match any file(s) known to git.
error: pathspec 'controller' did not match any file(s) known to git.
error: pathspec 'and' did not match any file(s) known to git.
error: pathspec 'views' did not match any file(s) known to git.
Davids-MacBook-Pro:blog daviddotterweich$ git commit -m 'added new controller and views'
[master a75eaea] added new controller and views
15 files changed, 105 insertions(+), 3 deletions(-)
create mode 100644 app/controllers/say_controller.rb
create mode 100644 app/helpers/home_helper.rb
create mode 100644 app/helpers/say_helper.rb
create mode 100644 app/views/say/filenames.erb
create mode 100644 app/views/say/goodbye.html.erb
create mode 100644 app/views/say/hello.html.erb
create mode 100644 app/views/say/say_goodnight.html.erb
create mode 100644 test/functional/home_controller_test.rb
create mode 100644 test/functional/say_controller_test.rb
Davids-MacBook-Pro:blog daviddotterweich$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment