문제

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

도움이 되었습니까?

해결책

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

다른 팁

There's an end too much.

Be more careful with your code indentation and this will never be a problem. Example on how it would look in Vim under. I just used =G and it aligned it for me. Additionaly, it'll only highlight the correct use of end. Your favorite editor of choice should have this functionality too. If not, switch.

enter image description here

try 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top