Git Product home page Git Product logo

apartment-app-esbuild's Introduction

Apartment app

$ rails new apartment-app-esbuild -d postgresql -T -j esbuild
$ bundle add rspec-rails
$ rails g rspec:install
$ rails db:create
$ bundle add devise
$ rails g devise:install
$ rails g devise User
$ rails g scaffold Apartment street:string city:string state:string manager:string email:string price:string bedrooms:integer bathrooms:integer pets:string image:text user:references --api
$ rails db:migrate
$ rails g controller app home
$ rails g stimulus react

Change in route.rb

get '*path', to: 'app#home'
root 'app#home'
  • Make sure to add instance variables you want to pass to the react side. (Devise works without adding here)
class AppController < ApplicationController
  def home
    @apartments = Apartment.all.to_a.to_json
  end
end
  • Change in views/app/home.html.erb
<%= content_tag(:div, "", id:"app", data: {
    controller: "react",
    react_apartments_value: @apartments,
    react_user_value: {
       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
     }
})%>

Change in javascript/controllers/react_controller.js

import { Controller } from "@hotwired/stimulus"
import React from "react"
import { createRoot } from "react-dom/client"
import App from "../components/App"
import { BrowserRouter } from "react-router-dom"

// Connects to data-controller="react"
export default class extends Controller {
  static values = {
    apartments: String,
    user: Object
  }
  
  connect() {
    const apartments = JSON.parse(this.apartmentsValue)
    const user = this.userValue
    console.log("React controller connected!")
    console.log("prop test: ", apartments)
    App.defaultProps = {
      apartments: apartments,
      user: user
    }
    const app = document.getElementById("app")
    createRoot(app).render(
      <BrowserRouter>
        <App />
      </BrowserRouter>
    )
  }
}

Start

bin/dev

Heroku Deployment

make sure Procfile exists and inside add

web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

link github repo to heroku add node.js buildpack (ruby should already be added) use heroku console to run

rails db:migrate
rails db:seed

Adding Tailwind

bundle add tailwindcss-rails
rails tailwindcss:install

make sure you leave the Procfile.dev alone when prompted.

Check application.thml.erb because it adds a flexbox in the main.

apartment-app-esbuild's People

Contributors

don-yoon avatar

Stargazers

Austin Walker avatar

Watchers

 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.