Class: RecoursesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RecoursesController
- Includes:
- Pagy::Method
- Defined in:
- app/controllers/recourses_controller.rb
Overview
Superclass of the controllers the gem defines when a host app has none.
Instance Method Summary collapse
-
#create ⇒ Object
Saves a submitted record, then shows the index again or redraws the form.
-
#edit ⇒ Object
Shows the form for the record the id names, which is already known to exist.
-
#index ⇒ Object
Lists one page of the model the route is named after.
-
#new ⇒ Object
Builds a blank record under the name Rails would use: @contact for contacts.
-
#update ⇒ Object
Saves changes to a record, then shows the index again or redraws the form.
Instance Method Details
#create ⇒ Object
Saves a submitted record, then shows the index again or redraws the form.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/recourses_controller.rb', line 21 def create record = assign resource_class.new(resource_params) if record.save flash.notice = "#{human_name} was created." redirect_to url_for(action: :index), status: :see_other else flash.now.alert = "#{human_name} could not be created." render :new, status: :unprocessable_entity end end |
#edit ⇒ Object
Shows the form for the record the id names, which is already known to exist.
34 |
# File 'app/controllers/recourses_controller.rb', line 34 def edit; end |
#index ⇒ Object
Lists one page of the model the route is named after.
11 12 13 |
# File 'app/controllers/recourses_controller.rb', line 11 def index @pagy, @resources = pagy resource_scope end |
#new ⇒ Object
Builds a blank record under the name Rails would use: @contact for contacts.
16 17 18 |
# File 'app/controllers/recourses_controller.rb', line 16 def new assign resource_class.new end |
#update ⇒ Object
Saves changes to a record, then shows the index again or redraws the form.
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/recourses_controller.rb', line 37 def update if @recourse.update resource_params flash.notice = "#{human_name} was updated." redirect_to url_for(action: :index), status: :see_other else flash.now.alert = "#{human_name} could not be updated." render :edit, status: :unprocessable_entity end end |