corincerami / mars-photo-api

A Rails API for photo data from NASA's Mars Rovers
https://api.nasa.gov/#MarsPhotos
GNU General Public License v3.0
358 stars 48 forks source link

Non-breaking syntax error in latest_photos_controller.rb #145

Closed mtilda closed 1 year ago

mtilda commented 3 years ago

I noticed the following syntax error in mars-photo-api/app/controllers/api/v1/latest_photos_controller.rb

class Api::V1::LatestPhotosController < ApplicationController
  def index
    def index
      @rover = Rover.find_by name: params[:rover_id].titleize
      if @rover
        render json: search_photos, each_serializer: PhotoSerializer, root: :latest_photos
      else
        render json: { errors: "Invalid Rover Name" }, status: :bad_request
      end
    end
  end
  ...
end

Notice how the index method is defined twice and nested inside of itself. I am really surprised this doesn't actually throw any errors. I already fixed this in the branch I am working on, which I will make a pull request for soon.

Let me know if there is something I'm not understanding here and this is actually how we want to keep it.

corincerami commented 3 years ago

You’re correct, this is a non breaking issue, although oddly enough it will work as expected because of the way Ruby works. A pull request to fix it would be appreciated.