Rails edit gem in production - ruby-on-rails

I am trying to edit a specific gem:
https://github.com/rderoldan1/md_simple_editor
The issue is that the editor does not load without a page refresh first.
The issue can be checked here: https://github.com/rderoldan1/md_simple_editor/issues/9
I was able to fix this in my local by editing the file:
/usr/local/rvm/gems/ruby-2.3.4/gems/md_simple_editor-0.3.0/app/assets/javascripts/md_simple_editor.js.coffee
It is fixed by just editing the code as the other users are saying in the issue posted in the gem url above.
I cant find the right place to fix this in production, can someone point me in the right directory path?
Thanks in advance.

Don't do it that way. Fork the gem, make the changes in the gem code and make sure you write tests that prove your code works as expected. Then push the code to your forked repo on github.
Then make a pull request and support the open source community. In the mean time, you can use your version of the gem by edit your Gemfile like so:
gem 'md_simple_editor', github: 'lacostenycoder/md_simple_editor', branch: 'master'
Of course replace lacostenycoder with your github username.

Related

pdf.js gem producing errors

I am a rails novice and trying to create my web portfolio in Cloud9. I wanted to display my resume.pdf in the user browser so I installed this gem gem 'pdfjs_rails' now my app doesn't even start in cloud 9. It show the following error messages in the terminal:
Please help me. How can i revert it back? thanks
Doesn't look like anything related to pdfjs (no point in that direction). Are you sure you've selected the right runner in Cloud9? See:
https://community.c9.io/t/error-when-running-ruby-project/11799/4
More in general: if you think an issue would be related to a gem, you can simply remove it from the Gemfile and run gem bundle to 'revert' to a previous state.

My CkEditor not looking good in Active Admin

My CkEditor look like see image
Can you help me please...
I want to display ckeditor like on http://ckeditor.com/demo
This issue is in active admin. I want to use ckeditor on active admin.
My Active Admin version is = 0.6.0
This issue is related to a change in Active Admin CSS style described in this issue:
https://github.com/gregbell/active_admin/issues/1852
There is also a pull request awaiting merging: https://github.com/gregbell/active_admin/pull/1952
For temporary fix i'm using my cloned version with this diff applied:
gem 'activeadmin', :git => "git#github.com:kars7e/active_admin.git"
The offending CSS is the reset style which unfortunately has higher importance than CKEditor styles.
EDIT:
The maintainers of original repo have merged the fix and it's working correctly.
probably something is missing, try inspect element( chrome browser) and reload the page,see if there is some error where something is not loaded because you got the thing, just styling is incorrect.
Had the same issue, code in following wiki page helped a little....
https://github.com/gregbell/active_admin/wiki/Ckeditor-integration
You can use this fix: https://gist.github.com/SebAshton/4690552 (it worked well for me)

SCRIPT14: Not enough storage is available to complete this operation, ckeditor gem error on IE

I'm using ckeditor gem in my rails app and its not working on IE. It gives an error
SCRIPT14: Not enough storage is available to complete this operation.
ckeditor.js?body=1, line 63 character 140
I search it on google and saw some result (http://krasimirtsonev.com/blog/article/CKEditor-Not-enough-storage-is-available-to-complete-this-operation and http://ckeditor.com/forums/Support/Not-enough-storage-error-IE7IE8) but I can not understand how can i implement it on my rails app using gem "ckeditor_rails", "~> 4.0.2". please help!
according to http://krasimirtsonev.com/blog/article/CKEditor-Not-enough-storage-is-available-to-complete-this-operation
how to implement it?
1) please copy vendor/assets/javascripts/ckeditor/ckeditor.js from ckeditor_rails gem to app/assets/javascripts/ckeditor/ckeditor.js of your project.
2) find
if(this.$.createStyleSheet)this.$.createStyleSheet
and replace with
if(false)this.$.createStyleSheet
3) cleanup cache of your browser and restart your server to see if it works.
honestly say, I don't try it for IE. But that's how rails assets pipeline works.
the new release v4.1 also has this piece of code. the bug may not be resolved by CKEDITOR team.
also see https://github.com/tsechingho/ckeditor-rails/issues/17

Ruby on Rails: How do I use a Gem? (Vacuum Amazon API)

I found an Amazon Gem that I want to use https://github.com/hakanensari/vacuum/.
I've only ever used gems with in depth tutorials or following a RailsCast. I'm looking for tips on using gems I find online. I'll explain the steps I'm doing, and hopefully someone can give me some ideas on what else I should be doing when using a new gem. Also, if you have a good tutorial or explanation on gems, that would be great too.
I started off examining the Gem on Github, I'll point out the things I took notice of. Let me know if there are things I'm missing I should notice.
Examining Gem on Github
Go to the examples and look at "examples/product_advertising/basic_lookup.rb"
Follow the required file, and checkout "examples/product_advertising/shared.rb"
Notice, I need to install "pry"
Notice, the examples expand on the "lib" folder
Check out "credentials.yml"
Notice a "#req" is instantiated as a new Vacuum object.
Then back in basic_lookup.rb, it looks like it's assigning the lookup value, then binding the response to some kind of "pry" view.
Next, I'll try implementing these examples in my own project. Here's where I'm not sure what to do as far, as files are concerned.
Attempt Implementing Example
Install vacuum gem
gem install vacuum
Install pry gem
gem install pry
Added "shared.rb" and "credentials.yml" to my "app/controllers" directory
Replaced the information in "credentials.yml" with my information
Attempt to copy the information from "basic_lookup.rb" into an existing controller
def amazon
require File.expand_path('../shared.rb', __FILE__)
res = #req.look_up '0816614024'
items = res.find 'Item'
binding.pry
end
Create a route
match '/test' => 'products#amazon'
Go to test page and receive the following error
undefined method 'look_up' for nil:NilClass
I would like to point out, at this point I haven't added the lib folder.
Questions
I like the credentials.yml is separated out, when I want to add this to my project, where should I save that file?
I like the shared.rb file, should I just put that in the controller folder?
Why is it referencing the "lib" folder in "shared.rb"? Do I need to copy that directory into my project?
I appreciate you sticking around and reading all of this. I'm still trying to get a handle on using a gems, so any help or tips are great. Really, I'm just trying to figure out, how do I find any gem and start using it appropriately.
Thanks for any help you can give me!
I like the shared.rb file, should I just put that in the controller folder?
Answer = yes, you just put that file in controller folder.

Modify Gem, then ensure it gets reloaded?

I've got a gem that I'm modified a bit of code in, but when I bundle install or update, the changes to the gem aren't reflected in my app. Is there a way to ensure the changes are captured and reloaded in my app? Thanks.
You should never update code directly in the gem. Instead, choose from one of these options (from preferred to less preferred):
Send a pull request to the gem maintainer
Monkey patch the gem in your app
Fork the original gem and maintain your copy.
If you need help with any of this, that's a topic for another discussion, but please, don't edit code in the gem itself.
Make sure you modify the installed gem by using bundle open . Make the changes, save, then if your app is local and running in standard development mode (no caching) the changes will be immediate and worse case you can restart your app and they will be picked up. If not, you aren't making the change to the gem your app is using. A change like this will survive a bundle install, because bundler will have no reason to update your gem. However, if you run bundle update and a new version of the modified gem is installed it will get rid of your change. A good approach is to fork the original gem on github, make your change and have your app point to your forked copy on github.. then even when you deploy the app it will find and install your modified code. Also if the change is something useful for everyone, make a pull request to the original project.

Resources