简体   繁体   中英

Should I copy/paste all controllers and routes from Spree to my own app?

I'm in process of learning RoR, and obviously Spree and few things aren't clear to me. I'm not totally familiar with Rails engines neither.

My question is should I copy all controllers and routes from Spree github page and then to overwrite them or they are already "booted" through engine?

Also, I noticed that some people use Deface to overwrite things on their own applications. Isn't it easier to copy/paste from github code and then modify it or there is some trick with it?

Thanks

The whole idea of gems is that they are package distribution mechanism that you can use instead of copy-pasting code.

Most modern languages have some sort of package distribution. Ruby's package manager of choice is Bundler .

It should always be used instead of copy-pasting because:

  1. Copy-pasting is error prone and tedious.
  2. You're not bloating your code repository with vendor code which makes it easier to maintain.
  3. Package managers can do dependency tree resolution to ensure that your dependencies are compatible with each other.
  4. Its not 1995 and copy-pasting a library will cast doubts on your competency.

If you need to modify a gem for whatever reason you can fork the repository and tell bundler to use your fork. But in most cases this is a last resort as Ruby is an extremely flexible language.

My question is should I copy all controllers and routes from Spree github page and then to overwrite them or they are already "booted" through engine?

No. Just mount the gem. In all likelihood its very configurable and provides options to customize it to your hearts intent without changing any of the gems code.

Or in many cases you can just use object oriented programming to configure your own subtypes of the controllers provided by the gem.

Deface is used to modify views after they are rendered. Its basically a more refined version of using a regular expression and thus quite hacky if the problem can be solved in the first place by using partials or helpers to make the code more modular. It has nothing to do with routes or controllers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM