How to convert a large gem to standalone rails app

2020-04-19 06:28发布

问题:

I'm building a social network and have been using the gem community_engine but have been having trouble implementing the large amount of customization that I need for my app. I figure this will make it easier for me to override and add methods, as well as help me to better understand and learn from the code since I will be able to actually see all of it in action.

So far in my attempt I downloaded the source code, added the default bin directory and config files that were missing, as well ass all the gem dependencies.

What else do I need to do to get the app to work? I realize that there may still be a lot and that it might not be easy to explain, but at the very least is there any sort of documentation out there that might help me understand how to convert the gem to a Rails application?

Heres the community_engine repo: https://github.com/bborn/communityengine

Because this idea may draw some criticism, I'll add that I was originally building the app without any huge plugins accept for devise however I'm running out of time to finish this.

More stuff I've tried:

Moving files to a new rails app, got server to run but encountered many seemingly random errors, fixed a few but more just seem to pop up that I cant figure out:

I also took a look at http://guides.rubyonrails.org/plugins.html but this gem seems to go beyond that.

回答1:

I would suggest that you clone the gem and begin copying files from the gem into your a new Rails application.

The engine gem probably has a similar structure to a Rails application, so you should be able to move the files from the corresponding folder to the same folder in your Rails root folder.

You may need to move gem files out of modules, change namespaces etc. Relevant folders to look at files you'll want to include might include app/ config/ db/, any gem dependencies in Gemfile or the gemspec file, as well as spec/ or test/.

Beyond that I think there's no silver bullet answer to your question, you're just going to have to work through problems until you have this up and running, and perhaps ask subsequent questions if you hit on an obstacle that you don't get beyond.



回答2:

I think what you're looking for is a way to hook your Rails Engine into a rails app. The Hooking Into an Application section of the Getting Started with Rails Engines guide should be exactly what you're looking for.

Here are two additional resources on Rails Engines.

A Guide to Rails Engines in the Wild

Rails::Engine - Ruby on Rails API