Module: Rows::Resources

Included in:
RowsController
Defined in:
lib/rows/resources.rb

Instance Method Summary collapse

Instance Method Details

#resourceObject



2
3
4
# File 'lib/rows/resources.rb', line 2

def resource
  @_resource || set_resource
end

#resourcesObject



6
7
8
# File 'lib/rows/resources.rb', line 6

def resources
  @_resources || set_resources
end

#set_resource(row = nil) ⇒ Object



10
11
12
13
14
15
# File 'lib/rows/resources.rb', line 10

def set_resource(row = nil)
  row ||= model_class.find_by_id(params[:id].to_i)
  instance_variable_set(:"@#{model_symbol}", row)
  @_resource = row
  @row = row
end

#set_resources(rows = nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/rows/resources.rb', line 17

def set_resources(rows = nil)
  rows ||= model_class.all
  instance_variable_set(:"@#{model_symbol_plural}", rows)
  @_resources = rows
  @rows = rows
end