Skip to content

Instantly share code, notes, and snippets.

@scottweisman
Created May 7, 2012 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottweisman/2628768 to your computer and use it in GitHub Desktop.
Save scottweisman/2628768 to your computer and use it in GitHub Desktop.
Using current_kase method in views
# concerns#current
module Current
extend ActiveSupport::Concern
...
def current_kase
@current_kase ||= Kase.find_by_id(params[:kase_id])
end
# To include methods in views
def self.included m
return unless m < ActionController::Base
m.helper_method :current_user, :current_kase
end
end
# sources#controller
def index
# nothing here
end
# sources#index
<h1><%= current_kase.name %></h1>
<%= link_to "Add source", new_kase_source_path %>
<% if current_kase.sources.any? %>
<% current_kase.sources.each do |source| %>
<h3><%= link_to source.name, kase_source_path(current_kase, source) %></h3>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment