How to add middleware in Rails 4.2 application
Middleware has to have an accompanying module / class, and needs to be loaded in the app before it can be referenced. The way to do this in Rails is with autoloading
(lib
files aren't autoloaded by default):
#config/application.rb
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.middleware.use "ResponseTimer"
The above should work for you.
how display certain branch of blog?
Okay, I've written about this before; there are certain things which you've got to fix with the Railscast recommendations:
- Put it in a partial, not helper (it gives greater autonomy)
- You need to make sure your structure is as versatile as you need
--
Here's how I'd do what you're trying to achieve:
#app/controllers/messages_controller.rb
class MessagesController < ApplicationController
def index
@messages = Message.all #-> could filter this to only retrieve id=3
#@messages = Message.find "3" #-> like this
end
end
#app/views/messages/index.html.erb
<% render @messages.arrange(order: :created_at) %>
#app/views/messages/_message.html.erb
# ... single message output code ... #
<%= render message.children if message.has_children? && message.id == "3" %>
You could then extrapolate the conditional functionality into a helper. If you describe your functionality more specifically, I'll be able to make a helper to define it.
Any gem for designing a blog post in Rails with syntax highlighting and inline image attachment?
Obtvse, an open source blog engine inspired by Svbtle does pretty much exactly what you are looking for.
It uses Coderay for syntax highlighting which is a pure ruby library and does not depend on javascript, and Markdown (through Kramdown) for editing posts rather than a WYSIWYG solution like CKEDITOR which IMHO is a more sane choice - especially for technically inclined.
Backend based syntax highlighting plays well with RSS readers as opposed to javascript based solutions.
You can either use the application and customize as per your requirements, or take a look at the implementation and use that to build your own solution.
Alternatively if you are specifically inclined towards using CKEditor you might want to take a look at this plugin which integrates CKEditor with CodeMirror, which is among the most popular solutions for code editing and highlighting in javascript. For displaying the snippets you can also use CodeMirror in a readonly mode as described in this manual. This will ensure that you get the exact same syntax highlighting while editing as well in post view page.
Related Topics
Ruby Gets/Puts Only for Strings
How to Have Rspec Test for My Default Scope
How to Find Each Instance of a Class in Ruby
Creating Permutations from a Multi-Dimensional Array in Ruby
Converting from Xml Name-Values into Simple Hash
Net::Ssh Sudo Command Hangs After Entering Password
Regex, How to Match Multiple Lines
How Is Each_With_Object Supposed to Work
Ruby - Digest::Digest Is Deprecated; Use Digest
Rails 3 Install Error: "Invalid Value for @Cert_Chain"
How to Create a Hash in Ruby That Compares Strings, Ignoring Case
To_Specs': Could Not Find Chef (>= 0) Amongst [] (Gem::Loaderror)
How to Test 'Rand()' with Rspec
How to Get Past "Http://Gems.Rubyforge.Org/ Does Not Appear to Be a Repository" Error Message
How to Write a Ruby Switch Statement (Case...When) with Regex and Backreferences