diff options
Diffstat (limited to 'app/controllers/route_sections_controller.rb')
| -rw-r--r-- | app/controllers/route_sections_controller.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/app/controllers/route_sections_controller.rb b/app/controllers/route_sections_controller.rb new file mode 100644 index 000000000..64cb8c65c --- /dev/null +++ b/app/controllers/route_sections_controller.rb @@ -0,0 +1,70 @@ +class RouteSectionsController < ChouetteController + + defaults :resource_class => Chouette::RouteSection + + respond_to :html + respond_to :kml, :only => :show + + belongs_to :referential + + before_action :save_return_to_path, only: [:edit, :create_to_edit] + before_action ->(controller) { build_breadcrumb controller.action_name } + + helper_method :search + + def index + index! + end + + def new + @stop_areas = referential.stop_areas.with_geometry.order :name + new! + end + + def show + @map = RouteSectionMap.new(resource).with_helpers(self) + show! + end + + def edit + @map = RouteSectionMap.new(resource, true).with_helpers(self) + edit! + end + + def update + update! { session.delete(:return_to) } + end + + def create + create! { session.delete(:return_to) } + end + + def create_to_edit + route_section = Chouette::RouteSection.create(route_section_params) + redirect_to edit_referential_route_section_path(referential, route_section) + end + + protected + + def save_return_to_path + session[:return_to] = params[:return_to] if params[:return_to] + end + + def collection + # if q = params[:q] + # @route_sections ||= Chouette::RouteSection.joins(:departure, :arrival).where(departure: {name: "#{q}"}).or.where(arrival: {name: "#{q}"}) + # end + @route_sections ||= search.collection.includes(:departure, :arrival).paginate page: params[:page] + end + + def search + @search ||= RouteSectionSearch.new(params[:route_section_search]) + end + + private + + def route_section_params + params.require(:route_section).permit(:departure_id, :arrival_id, :editable_geometry, :no_processing) + end + +end |
