Rendering a view from my Ruby on Rails Gem
The "correct" way to do this since Rails 3 is to create an Engine
; there's also a Rails guide for this, but creating a basic engine is as easy as:
module MyGemName
class Engine < Rails::Engine
end
end
When Rails looks for a view to render, it will first look in the app/views
directory of the application. If it cannot find the view there, it will check in the app/views
directories of all engines that have this directory. Render Custom views instead of default Devise views- Rails
Overriding the default Devise’s views
is simple and straight forward, what we need to do is just generate those views in our app/views
folder by the following single command.
rails g devise:views
The following views
are generated.app/views/devise/confirmations
app/views/devise/mailer
app/views/devise/passwords
app/views/devise/registrations
app/views/devise/sessions
app/views/devise/shared
app/views/devise/unlocks
No other changes are necessary.Or if you have already done it,you need to move folders inside
app/views/devise
Railtie(gem): How do i include and render erb partials?
After a lot of trail and error i managed to get it working. This is what i had to do:
I changed this:
initializer 'embeddable.add_view_paths', :after => :add_view_paths do |app|
ActiveSupport.on_load(:action_controller) do
append_view_path app.root.join("lib/embeddable/").to_s
end
end
Into this:initializer 'embeddable.add_view_paths', :after => :add_view_paths do |app|
ActiveSupport.on_load(:action_controller) do
append_view_path "#{Gem.loaded_specs['embeddable'].full_gem_path}/lib/embeddable"# <- this is the change
end
end
Now i can render partials from the helper like this:render 'partials/youtube', id: video_id, width: width, height: height
Related Topics
How to Get Meta Keywords Using Nokogiri
Ruby 1.9 How to Convert Array to String Without Brackets
How to Scrape a Website with The Socksify Gem (Proxy)
Filtering Sensitive Data with Vcr
Ruby Rspec. Get List of All Test
Parsing a CSV File Using Different Encodings and Libraries
How to Evaluate a Block Inside a Proc
How to Run Capybara-Webkit (I.E. Forked Webkit_Server) on Heroku Cedar
Sha1 Hashes Not Matching Between My Rails and Cocoa Apps
What Is The Ruby Equivalent to This Curl Request
Nlp to Classify/Label The Content of a Sentence (Ruby Binding Necesarry)
Where Is Ruby's Erb Format "Officially" Defined
How to (Massively) Reduce The Number of SQL Queries in Rails App