Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Forked from anonymous/example.rb
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecmpbll/511c10497862e0143427 to your computer and use it in GitHub Desktop.
Save mikecmpbll/511c10497862e0143427 to your computer and use it in GitHub Desktop.
class Widget < ActiveRecord::Base
attr_accessible :name, :snippets, :snippets_attributes, :company_id, :hostname, :first_page, :affiliate_id, :item_defaults, :read_only
has_many :snippets
has_many :permissions, dependent: :destroy
has_many :users, through: :permissions
accepts_nested_attributes_for :snippets
attr_accessor :read_only
def read_only
true
end
def attributes
super.merge({'read_only' => read_only})
end
end
def widget
@hide_nav = true
@widget = Widget.find_by_url(params[:id])
@widget = Widget.find_by_id(params[:id]) unless @widget
@widget.read_only = !current_user.has_role? :admin
render 'widget' , layout: 'edit_widget'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment