# Plugin using own gem

**URL:** https://meta.discourse.org/t/plugin-using-own-gem/50007
**Category:** Development
**Created:** [September 12, 2016, 11:11am UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007 "2016-09-12T11:11:58Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 12, 2016, 11:11am UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/1 "2016-09-12T11:11:58Z")

</div>

I am developing a plugin that needs to use an external gem, namely docx in order to generate word docs.

Is there someway to do this or do I have to append it to the Gemfile?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [September 12, 2016, 12:29pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/2 "2016-09-12T12:29:14Z")

</div>

There is a way to do it. You put the following in your plugin.rb file

```plaintext
gem 'omniauth-linkedin-oauth2', '0.1.5'

```

Example of usage:

> <https://github.com/discourse/discourse-linkedin-auth/blob/main/plugin.rb>

---

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 12, 2016, 7:37pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/3 "2016-09-12T19:37:15Z")

</div>

Thanks, gave it a go but get the following error message:

```plaintext
/home/kiffin/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'rubyzip' (~> 1.1.6) among 186 total gem(s) (Gem::LoadError)

```

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [September 12, 2016, 7:45pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/4 "2016-09-12T19:45:30Z")

</div>

Did you run `bundle install` after adding the gem?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [September 12, 2016, 8:17pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/5 "2016-09-12T20:17:28Z")

</div>

Yeah on your dev machine you will have to do bundle install. Docker does that for you, I believe.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 12, 2016, 9:27pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/6 "2016-09-12T21:27:14Z")

</div>

Gems declared in a plugin are installed and loaded differently as per our implementation:

> <https://github.com/discourse/discourse/blob/main/lib/plugin/instance.rb#L353-L381>

In order to get it to work, you’ll have to specify all the gem’s dependencies which are not already included in the Gemfile.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 14, 2016, 7:53pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/7 "2016-09-14T19:53:52Z")

</div>

> [@kgish](#):
>
> namely docx in order to generate word docs.

What’s your plugin going to do? I’ve got a client who would love to be able to export a topic as a Word document.

---

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 14, 2016, 9:04pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/8 "2016-09-14T21:04:12Z")

</div>

I’ve created a plugin that does just that, click on the word-icon, interested?

 ![](https://global.discourse-cdn.com/meta/original/3X/5/5/5519e1dba3e14499ebc8e5fe22a37219ea87ac10.png)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 14, 2016, 9:07pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/9 "2016-09-14T21:07:49Z")

</div>

I"m sure she will be. I just wrote a Ruby program that takes either a topic or category URL on the command line and downloads a topic (or all of them in the category) as a sort-of MBOX file with headers like these:

```bash
From username 1365 2016-07-18T02:20:41.074Z
Name: Jay User (username)
Subject: Week 7 Discussion
Date: 2016-07-28T02:20:41.074Z
Post: 10
Reply-to: 9
Num-Replies: 0
Read-time: 30
Times-read: 21
Post-URL: https://literatecomputing.com/t/79/10

```

followed by either the HTML or the raw Markdown text.

---

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 14, 2016, 9:58pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/10 "2016-09-14T21:58:20Z")

</div>

I guess that’s one way of doing it. My method however does something similar and delivers the generated doc directly to the user.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 14, 2016, 10:03pm UTC](https://meta.discourse.org/t/plugin-using-own-gem/50007/11 "2016-09-14T22:03:56Z")

</div>

I’m very interested in seeing your code!
