ruby-grape / grape-rabl

Use rabl with grape
MIT License
136 stars 29 forks source link

render doesn't work properly #29

Closed ShPakvel closed 9 years ago

ShPakvel commented 10 years ago

Render from example doesn't work properly. I mean this part:

  get '/user/:id', :rabl => 'user' do
    @user = User.find(params[:id])

    if @user.admin?
      # overwrite the template (and pass locals) with the #render method
      render rabl: 'admin', locals: { details: 'this user is a admin' }
    end
  end

Workaround like following helps and works fine:

  get '/user/:id' do
    @user = User.find(params[:id])

    if @user.admin?
      # overwrite the template (and pass locals) with the #render method
      render rabl: 'admin', locals: { details: 'this user is a admin' }
    else
      render rabl: 'user'
    end
  end

But in your example, after execution with render rabl: 'admin' has happened, it does all following execution with 'admin' template as well.

dblock commented 10 years ago

That would be a bug indeed. Do you think the example is just incorrect? We claim to be overriding things, but really we can't. I would split the example in 2) one with rabl: in the endpoint definition and another that does this programatically.

Care to PR?

ShPakvel commented 10 years ago

When I have time I'll look at code to help to solve problem. Right now I've just added PR with readme correction as your described above.

LTe commented 9 years ago

@ShPakvel @dblock I can not reproduce mentioned issue. I created tests for proof (https://github.com/LTe/grape-rabl/issues/32).

LTe commented 9 years ago

@ShPakvel re-open this issue in case of any problems.