diff --git a/app/controllers/equipment_controller.rb b/app/controllers/equipment_controller.rb index 50f9a393..f0c08839 100644 --- a/app/controllers/equipment_controller.rb +++ b/app/controllers/equipment_controller.rb @@ -15,8 +15,7 @@ class EquipmentController < ContentController def populate_universe_fields @universe = Universe.where(user_id: session[:user], name: params[:universe].strip).first - @equipment = - @equipment.where(universe_id: @universe.id) if @equipment.blank? + @equipment = @equipment.where(universe_id: @universe.id) if @equipment.blank? end def universe_from_equipment_params diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 92574dfd..b6a18f48 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -1,101 +1,8 @@ # Controller for the Location model class LocationsController < ContentController - - def index - @locations = Location.where(user_id: session[:user]) - .order(:name).presence || [] - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @locations } - end - end - - def show - @location = Location.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @location } - end - end - - def new - @location = Location.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @location } - end - end - - def edit - @location = Location.find(params[:id]) - end - - # rubocop:disable LineLength - def create - @location = create_location_from_params - - respond_to do |format| - begin - if @location.save - notice = t(:create_success, model_name: Location.model_name.human) if notice.blank? - format.html { redirect_to @location, notice: notice } - format.json { render json: @location, status: :created, location: @location } - else - format.html { render action: 'new' } - format.json { render json: @location.errors, status: :unprocessable_entity } - end - rescue Errno::ECONNRESET - # Connection was reset, probably because of the file upload. - # Try again without it. - @location.map = nil - notice = t :location_create_upload_map_error - retry - end - end - end - # rubocop:enable LineLength - - # rubocop:disable LineLength - def update - @location = update_location_from_params - - respond_to do |format| - begin - if @location.update_attributes(location_params) - notice = t :update_success, model_name: Location.model_name.human if notice.blank? - format.html { redirect_to @location, notice: notice } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @location.errors, status: :unprocessable_entity } - end - rescue Errno::ECONNRESET - # Connection was reset, probably because of the file upload. - # Try again without it. - @location.map = nil - notice = t :location_update_upload_map_error - retry - end - end - end - # rubocop:enable LineLength - - def destroy - @location = Location.find(params[:id]) - @location.destroy - - respond_to do |format| - format.html { redirect_to location_list_url } - format.json { head :no_content } - end - end - private - def location_params + def content_params params.require(:location).permit( :universe_id, :user_id, :name, :type_of, :description, :map, :population, :currency, :motto, :capital, :largest_city, :notable_cities, @@ -116,7 +23,6 @@ class LocationsController < ContentController end def universe_from_location_params - Universe.where(user_id: session[:user], - name: params[:location][:universe].strip).first + Universe.where(user_id: session[:user], name: params[:location][:universe].strip).first end end diff --git a/app/views/locations/_list.html.erb b/app/views/locations/_list.html.erb index 98cea567..97cef6f9 100644 --- a/app/views/locations/_list.html.erb +++ b/app/views/locations/_list.html.erb @@ -1,4 +1,4 @@ -<% @locations.each do |location| %> +<% @content.each do |location| %>