Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2014 15:07
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 anonymous/7a6da4e49977c8b65448 to your computer and use it in GitHub Desktop.
Save anonymous/7a6da4e49977c8b65448 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
if current_user.has_role? :admin
@widget.read_only = false
end
render 'widget' , layout: 'edit_widget'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment