Module: BTech::Rest::Actions

Included in:
BTech::Rest
Defined in:
lib/actions.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Default create action. Feel free to override.



42
43
44
45
46
47
48
49
# File 'lib/actions.rb', line 42

def create
  build_resources
  if get_record.update_attributes params[get_model_symbol]
    redirect_to build_resource_url(@resources)
  else
    render_new_or_edit_partial
  end
end

#destroyObject

Default destroy action. Feel free to override.



62
63
64
65
66
67
# File 'lib/actions.rb', line 62

def destroy
  build_resources
  get_record.destroy
  @resources.last.delete :record
  redirect_to build_resource_url(@resources)
end

#editObject

Default edit action. Feel free to override.



36
37
38
39
# File 'lib/actions.rb', line 36

def edit
  build_resources
  render_new_or_edit_partial
end

#indexObject

Default index action. Feel free to override.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/actions.rb', line 5

def index
  build_resources
  if @resources.size > 1
    # Records for a nested resource (act on the second-to-last parent).
    parent = @resources[@resources.size - 2][:record]
records_name = parent.class.name.underscore.pluralize
records = parent.instance_eval("#{@resources.last[:parent_resource_method] || @resources.last[:name]}").paginate :page => params[:page], :per_page => 10
  else
    # Records for single resource.
records_name = get_model_name
if records_name
	records_name = records_name.pluralize
	records = @resources.last[:model].all.paginate(:page => params[:page], :per_page => 10)
end
  end
				instance_variable_set "@#{records_name}", records if records_name
end

#newObject

Default new action. Feel free to override.



30
31
32
33
# File 'lib/actions.rb', line 30

def new
  build_resources
  render_new_or_edit_partial
end

#showObject

Default show action. Feel free to override.



24
25
26
27
# File 'lib/actions.rb', line 24

def show
  build_resources
				render_action_partial @resources.last[:show_partial]
end

#updateObject

Default update action. Feel free to override.



52
53
54
55
56
57
58
59
# File 'lib/actions.rb', line 52

def update
  build_resources
  if get_record.update_attributes params[get_model_symbol]
    redirect_to build_resource_url(@resources)
  else
    render_new_or_edit_partial
  end  
end