GithubHelp home page GithubHelp logo

learn-academy-2022-alpha / apartment-app-keelanpattersoncaesar Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 165 KB

apartment-app-keelanpattersoncaesar created by GitHub Classroom

Ruby 80.79% JavaScript 9.78% HTML 9.40% SCSS 0.03%

apartment-app-keelanpattersoncaesar's Introduction

README

Hello. This is my README for my Apartment Finder App.

First, we create a Rails App:

$ rails new apartment-app -d postgresql -T
$ cd apartment-app
$ rails db:create

Then, we install a bunch of different resources:

  • RSpec
  • $ bundle add rspec-rails
  • $ rails generate rspec:install
  • React
  • $ bundle add webpacker
  • $ bundle add react-rails
  • $ rails webpacker:install
  • $ rails webpacker:install:react
  • $ yarn add @babel/preset-react
  • $ yarn add @rails/activestorage
  • $ yarn add @rails/ujs
  • $ rails generate react:install
  • $ rails generate react:component App
  • Devise
  • $ bundle add devise
  • $ rails generate devise:install
  • $ rails generate devise User
  • $ rails db:migrate

Changed default route for mailer

  • config/environments/development.rb
  • Added:
config.action_mailer.default_url_options = { host:  'localhost', port:  3000 }

Changed request type for user logout

  • config/initializers/devise.rb
  • Replaced: config.sign_out_via = :delete

  • With: config.sign_out_via = :get

Rails Routing

  • rails g controller Home
create  app/controllers/home_controller.rb
invoke  erb
create  app/views/home
invoke  rspec
create  spec/requests/home_spec.rb
invoke  helper
create  app/helpers/home_helper.rb
invoke  rspec
create  spec/helpers/home_helper_spec.rb
  • Added a file in app/views/home called index.html.erb
<%= react_component  'App', {
logged_in:  user_signed_in?,
current_user:  current_user,
new_user_route:  new_user_registration_path,
sign_in_route:  new_user_session_path,
sign_out_route:  destroy_user_session_path
} %>
  • In app/views/layouts/application.html.erb, changed <%= javascript_importmap_tags %> to app/views/layouts/application.html.erb

  • In config/routes.rb, added routes:

get  '*path', to:  'home#index', constraints:  ->(request){ request.format.html? }
root  'home#index'

React Routing

  • Added React Router: $ yarn add [email protected]
  • In app/javascript/components/App.js, imported React Router

Adding Reactstrap

  • $ bundle add bootstrap
  • $ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
  • $ yarn add reactstrap

app/assets/stylesheets/application.scss

@import  'bootstrap';

Apartment Resource

  • Generating a resource:
  • $ rails g resource Apartment street:string city:string state:string manager:string email:string price:string bedrooms:integer bathrooms:integer pets:string image:text user_id:integer
  • $ rails db:migrate

User and Apartment Associations

Defining model-class relationship:

  • app/models/apartment.rb
class  Apartment < ApplicationRecord
belongs_to  :user
end
  • app/models/user.rb
class  User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise  :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many  :apartments
end

Getting Started with React

  • Created 3 folders in app/javascript/components
  • ./assets
  • ./components
  • ./pages
  • Foundation set in app/javascript/components/App.js
import React, { Component } from 'react'

class App extends Component {
  render() {
    const {
      logged_in,
      current_user,
      new_user_route,
      sign_in_route,
      sign_out_route
    } = this.props
    console.log("logged_in:", logged_in)
    console.log("current_user:", current_user)
    console.log("new_user_route:", new_user_route)
    console.log("sign_in_route:", sign_in_route)
    console.log("sign_out_route:", sign_out_route)
    return(
      <>
        <h1>Apartment App</h1>
      </>
    )
  }
}

export default App

apartment-app-keelanpattersoncaesar's People

Contributors

keelanpattersoncaesar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.