I am trying to use Deface gem for customizing a view that is located in gem (it is not spree).
The path to the view is:
my_gem/backend/layout/sidebar
When I run:
rake deface:test_selector['my_gem/backend/layout/sidebar','.mainnav ul']
I get two matches, the view and proper matching elements are correctly displayed.
However when I run:
rake deface:get_result['my_gem/backend/layout/sidebar']
nothing is changed in the view and apart from its code,"Overrides(0) found" is displayed.
My Override is located in: /app/overrides/add_slider_to_sidebar.rb file:
Deface::Override.new(:virtual_path => 'my_gem/backend/layout/sidebar',
:name => 'add_slider_to_sidebar',
:insert_bottom => ".mainnav ul",
gem:text => "<li>AAAAA</li>")
What should I change (or add to configuration) to allow deface to find my override?
I am using rails 4.0.5, deface 1.0.0 and nokogiri 1.6.2.1.
Edit:
I've made following tests:
Add deface to the application, and do the change mentioned above. Everything worked fine.
Add deface to the gem - so test in dummy application. The behavior described above has occurred.
Add gem with deface view modifications from point 2 but to regular application, not the dummy one. The above behavior has occurred.
Related
I'm trying to override view with Deface.
In manual creators called it standalone, so I guess that it's possible to use this gem without using spree... But I'm not sure anymore because nearly every tutorial/question/anything I found about Deface was related to spree.
However I tried. what I done was adding a line to Gemfile
gem 'deface'
and running
bundle install
which for sure installed deface gem.
Then I made route like this:
get 'test', to: 'test#show'
empty controller app/controllers/test_controller.rb
class TestController < ApplicationController
def show
end
end
and view like this app/views/test/show.html/erb
<h1 id="test">test first</h1>
then I go to cd app and make directory overrides mkdir overrides and created app/overriders/test_uploader.rb which contains:
Deface.Override.new(
:virtual_path => 'test/show',
:name => 'test uploader',
:replace => 'h1#test',
:text => '<h1 id="test">replaced, test passed</h1>'
)
But even if I reloaded server nothing happened.
Why? Had I missed something? Or maybe I really needs spree to use Deface?
Not sure why your code sample not working but I did simple sample also for you and its works very well. You can download code project here https://github.com/nezirz/deface_gem
Also here is a screen shoot:
So the coffeescript code shown in the attached view runs without a problem in my Rails 4.2.0 view, but is breaking in the Rails 5.1.2 upgrade with the messages shown: I have upgraded the gems shown below:
coffee-rails from 4.1.0 to 4.2.2
coffee-script-source from 1.9.0 to 1.12.2
And the haml_coffee_assets has always pointed to the master branch as shown below so no changes there:
gem 'haml_coffee_assets', git: "https://github.com/netzpirat/haml_coffee_assets"
Before I start to make crazy changes, I want to see if anyone else has run into similar problems. I am moving away from coffeescript in favor of the plain javascript in my newer Rails applications and have no problems with embedded javascript code. However, this is an older application that is not used heavily and I want to invest minimum time in maintaining it. There is too much Coffeescript code in it for me to convert it easily. If there is a site that will let me convert the coffeescript to Javascript without too many problems, then I would like to. The best solution would be to just keep going forward with what I have.
Has anyone run into this problem? Any ideas?
Here is the code:
- if #well.has_sense_graph?
#sensitivity.tab
= render :partial => "shared_wells/show_sensitivity", :locals => {:sensitivity => sense_hash[:sensitivity], :offset => sense_hash[:offset] }
%br
#discount_chart
:coffeescript
$ ->
model = new Backbone.Model
forecastTickInterval: #{graph_hash[:forecast_tick_interval]}
typeWell: #{#well.to_json}
x_labels: #{graph_hash[:price_array]}
disc_rate_array: #{graph_hash[:disc_rate_array]}
disc_pv10_array: #{graph_hash[:disc_pv10_array]}
ngl_array: #{ngl_vol_array}
view = new VGStream.Views.TypeWells.Show(
model: model
).render()
VGStream.App.router = new VGStream.Routers.Tabs()
VGStream.App.currentView = view
Backbone.history.start()
_.defer ->
$(document).scrollTop(0)
So I solved this problem in a practical way. Given the goal that I have to get rid of CoffeeScript code in my application and replace it with equivalent Javascript code, I did the following:
All pages where I have embedded CoffeeScript code in the haml pages as shown above in the code that I have provided, I replaced it with equivalent Javascript code as shown below:
:javascript
$(function() {
...
});
Note that I left the 'pure' coffeescript files, i.e., with extension '.coffee' stored in assets/javascript/... ' folders alone, since my more immediate goal is to get the Rails 5.1.2 upgrade done as quickly as possible.
For some reason that I do not know (nor do I care to know), the embedded coffeescript code no longer works for me as it did in the Rails 4.2.0 version. But since I do not care about CoffeeScript anymore, this hybrid solution is acceptable to me.
I want to customize the controller views generated by haml-rails. According to the Rails guide I am supposed to put my customized templates (e.g. index.html.haml) into lib/templates/[subfolders].
In this case I tried several subfolders (e.g. lib/templates/haml/scaffold, lib/generators/haml/scaffold/templates) but I could not get my custom templates to be used.
I know that I could write another generator easily, but I am wondering if there is a more DRY way to do so. In theory it should be possible:
In Rails 3.0 and above, generators don't just look in the source root for templates, they also search for templates in other paths.
I am using Rails (4.2.5.2), haml (4.0.7) and haml-rails (0.9.0).
Holy moly. It worked after all. It is correct to put the templates into lib/templates/haml/scaffold. And now comes the catch: spring will cache the templates. Hence, you must either restart spring after changes or prepend DISABLE_SPRING to the generator command:
DISABLE_SPRING=true rails g scaffold ...
I'm using the excellent twitter-bootstrap-rails gem. There is a helper within that gem (NavbarHelper) which is used to generate Bootstrap navbars with a Ruby helper. I want to monkey patch the gem such that the dropdown lists won't have carets.
So, I looked into the source and found the relevant method here. All I have to do is override it. I created a new file in config/initializers called navbar.rb with the following content:
NavbarHelper.module_eval do
def name_and_caret(name)
"HELLO WORLD"
end
end
Presumably, all of the dropdown titles then should be rendered as "HELLO WORLD" in my app (as referenced by the gem source). However, this is not occurring, and the gem does not appear to be monkeypatched at all.
I tried placing puts NavbarHelper.methods - Object.methods in the initializers file, and there were no results, which makes me think that Rails is not loading the gem correctly before the initializers. I have also checked and verified that the gem is not using autoload for its helpers.
Edit
What may be complicating this is the fact that my Gemfile includes the gem in the following manner:
gem 'twitter-bootstrap-rails', git: 'git://github.com/seyhunak/twitter-bootstrap-rails.git', branch: 'bootstrap3'
I'm not sure if this specific versioning means the monkeypatching doesn't work.
Edit #2
It seems there is only one version of the gem on my system, so I don't think that's the issue. Also, I have tried placing require 'twitter-bootstrap-rails at the top of the initializers file, with no results.
The problem is that you patch the method on this module but the module already got included at this point. Try to define this in your application_helper.rb
def name_and_caret(name)
super("blub #{name}")
end
i just installed the rails_admin admin gem to my existing rails app. Now i am wondering how do i add redcloth and/or ckeditor to it. When i add ckedtor, it just shows the description area and does not show the title and other fields. Also it does not format after saving. How do i edit the necessary files ?
Thanks
If it doesn't show buttons, it isn't the CKEditor, but the default text area, meaning insert CKEditor failed.
Things to check:
Make sure you set it on the fields, like so:
https://github.com/sferik/rails_admin/wiki/Text
Make sure you are using the correct gem version for your Rails (<3, >=3, >=3.2)
https://github.com/galetahub/ckeditor
Make sure you ran the generator, e.g.:
rails g ckeditor:install --orm=active_record --backend=carrierwave
Finally, check your browser console for errors.