Search code examples
rubysyntax-errorpadrino

Syntax error in content type case statement


This is my code in my Padrino application and I can't figure out what line or bug it is. The error message is "syntax error, unexpected keyword_end expecting $end"

get :index, :provides => [:html, :json] do
    @title = "Restaurants"
    @restaurants = Restaurant.all

    case content_type
      when :json
        render @restaurants
      else
        render 'restaurants/index'
      end
    end
  end

Could you please point out my mistake and also suggest how I might debug it in future? Thanks


Solution

  • You have one spare end keyword. You should remove one.

    There is a little mess with indentation in your code. Keeping right indentation helps a lot in avoiding such errors. I would suggest to indent your code like this:

    get :index, :provides => [:html, :json] do
      @title = "Restaurants"
      @restaurants = Restaurant.all
    
      case content_type
      when :json
        render @restaurants
      else
        render 'restaurants/index'
      end
    end