Restart Rails server automatically after every change in controllers

后端 未结 1 1956
一整个雨季
一整个雨季 2021-01-16 02:07

It should not be necessary to restart Rails server after any normal change. However, when I make little changes on my app controllers, they aren\'t applied if I don\'t resta

相关标签:
1条回答
  • 2021-01-16 02:43

    You can use nodemon for auto restarting your old rails applications.

    1) Install nodemon.

    sudo npm install -g nodemon
    

    2) Create nodemon.json file on root dir and configure it

    {
      "ignore": [
        ".git",
        "node_modules/**/node_modules"
      ],
      "watch": [
        "app/controllers/",
        "app/models/",
        "app/assets/",
        "config/",
        "db/"
      ],
      "ext": "rb yml js css scss"
    }
    

    3) Create rails.sh file on root dir to start rails application using nodemon.

    kill -9 `cat tmp/pids/server.pid`
    echo "APP READY!!!"
    echo "Ruby on Rails"
    rails s -d
    

    4) Give permission to rails.sh file.

    sudo chmod +x rails.sh
    

    5) Start server using sh command.

    nodemon -L --exec "./rails.sh"
    

    Note: Steps verified on mac machine. different os may have different command or configuration.

    0 讨论(0)
提交回复
热议问题