Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile
class Dog
def walk(location, distance)
@location = location
@distance = distance
end
end
tilly = Dog.new
tilly.walk("brighton", 5)
p tilly
@harrisonmalone
harrisonmalone / Animal.java
Last active October 12, 2018 00:37
basic java class which prints out the object id in the void main
public class Animal {
public Animal(String name) {
name = name;
}
public static void main(String[] args) {
Animal bear = new Animal("bear");
System.out.println(bear);
}
}
@harrisonmalone
harrisonmalone / Dog.java
Last active October 12, 2018 00:40
java class that uses a constructor but also sets instance variables to an instance later on, content taken from the a ruby challenge
public class Dog {
public static int walks = 0;
public String location = null;
public Dog(String name, int age) {
name = name;
age = age;
}
public void bark() {
@harrisonmalone
harrisonmalone / Car.java
Last active October 12, 2018 00:43
java example with getters and setters, also uses the date and scanner utils, scanner util is like gets in ruby
import java.util.Date;
public class Car {
private String brand;
private String colour;
private int wheels;
private Date date = new Date();
public Car(String brand, String colour) {
this.brand = brand;

Background & Objectives

In this challenge, you will meet your old friend Active Record, which is Rails' ORM.

Specs

Routing

Build a Rails todolist application. Your todo-app should have 7 entry points in the routing:

  1. GET '/tasks': get all your tasks.

Git and Github

Let's make it easy

Git is kind of like Google Docs.

It's the way developers save their code. It's also the way we can push our code to the cloud (GitHub) and collaborate with other developers. This whole process is called version control.

Google Docs has it's own kind of version control. In Git it's similar but more developer friendly because everything happens on the command line.

Rails App Structure

Now that you have created your first Rails App and started looking inside the application directory we know some of you hunger for the details of all the folders and files generated. So here is a quick rundown of what in each directory. Take your time and explore away.

app is where you'll put the majority of your application code. You'll be spending alot of time in here. Rails is very opinionated software so it place a lot of emphasis on keeping code organized, so the app directory has a number of sub-directories:

assets contains sub-directories where you'll store your application's images, JavaScript files, and stylesheets (CSS)

channels is where you put Ruby classes designed to handle real-time features using Action Cable

@harrisonmalone
harrisonmalone / index.html.erb
Last active October 21, 2018 11:30
bit.ly rails copy
<h1>Link shortener</h1>
<%= form_for(Link.new, url: link_path) do |f| %>
<%= f.text_field :original_url %>
<%= f.submit "Create short link" %>
<% end %>
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :dob])
end

Specs

1 - Model

Generate the Article model through the right rails generator. It should have at least the following columns:

  • title, as a string
  • content, as a text

Don't hesitate to crash test your new model in the rails console: