Convert Rails API to project back to regular?
Asked Answered
R

2

6

I've created a rails API project (Rails 5) to be the back end for my mobile application, but i would now like to create some administrative functions that I can access directly from a browser.

I'm not exactly sure what I need to do to restore all the web features of my rails project so that some of my controllers will service requests for web pages, and things like scaffolding will generate web pages instead of json responses.

Any suggestions appreciated.

Ripplet answered 6/12, 2017 at 4:21 Comment(0)
F
4

Just run rails new {your app name} on top of your application and press Y to overwrite the existing files. You can then use Git to look at the changes made and keep the changes that exist for a fresh Rails installation and also the changes you had made on your Rails API project. Run the tests to ensure everything still works and then you're good to go.

Fictive answered 6/12, 2017 at 4:35 Comment(3)
Will this delete any of my models, controllers or concerns that then need to be restored or do anything to the existing databases? Will it revert my gem file? Ive done quite a lot of work on the APIs and a bit paranoid about losing it all.Ripplet
No, it should only attempt to overwrite standard Rails files. But it you have your code in version control like Git then it shouldn't be an issue because you can easily view changes and revert them if necessary.Fictive
Hm. Turns out to be harder than it sounds for reasons I don't understand yet. I get an error when running rails new in the directory in which the application currently exists. Switching to its parent, when I try to run Rails new from there, I get an "install rails" message, which perplexes, since RubyMine has no trouble creating new applications for me. Finally, i just created a new non-api rails app with Rubymine and examined the system genrated rails files for differences. I was able to get it to work as expected but hope I didn't miss anything.Ripplet
H
0

I just did this and it seems to be working fine now.

  • Make sure you commit everything
  • Make a blank rails app outside of your rails repo
  • Copy the app your converting (backup) to another directory outside of your repo
  • Copy (overwrite) the blanks rails app in to the app you are converting
  • Copy (overwrite) the backup on to the app you are converting
  • Check the git status, look at the pull request, make sure node_modules is included in .gitignore
  • I double check these files, compare them to the blank app:
 gemfile
 .gitignore
 application.rb
 development.rb
 production.rb
 application_controller.rb (You will need to change what is inherited)

If you need a reference these are the file changes I had when I was done:

  (use "git restore <file>..." to discard changes in working directory)
        modified:   .gitignore

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        app/assets/images/
        app/assets/stylesheets/
        app/helpers/
        app/javascript/
        app/views/layouts/application.html.erb
        babel.config.js
        bin/webpack
        bin/webpack-dev-server
        bin/yarn
        config/initializers/assets.rb
        config/initializers/content_security_policy.rb
        config/initializers/cookies_serializer.rb
        config/webpack/
        config/webpacker.yml
        lib/assets/
        package.json
        postcss.config.js
        public/404.html
        public/422.html
        public/500.html
        public/apple-touch-icon-precomposed.png
        public/apple-touch-icon.png
        public/favicon.ico
        test/application_system_test_case.rb
        test/channels/
        test/helpers/
        test/system/
        tmp/pids/
        yarn.lock
Hartman answered 15/1, 2021 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.