Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to 0.5.0 from 0.4.3 encountering error "undefined method `render' for RablRails:Module" #88

Open
jiggneshhgohel opened this issue Aug 3, 2017 · 6 comments

Comments

@jiggneshhgohel
Copy link

jiggneshhgohel commented Aug 3, 2017

Hello,

In our Rail-based API-only app we are generating JSONs by rendering object directly.

There are cases when you want to render object outside Rails view context. For instance to render objects in the console or to create message queue payloads. For these situations, you can use RablRails.render as show below:

RablRails.render(object, template, :view_path => 'app/views', :format => :json) #=> "{...}

Recently we have started upgrading our Rails to 5.1.2 and as part of bundle update rabl-rails gem got updated to v 0.5.0 from 0.4.3 (bundle update output snippet)

Fetching rabl-rails 0.5.0 (was 0.4.3)
Installing rabl-rails 0.5.0 (was 0.4.3)

Now we are running our rspec and encountering following error:

     Failure/Error: RablRails.render(serializable_object, template.name, view_path: template.root_path_for_api_version.to_s, format: :json)
     
     NoMethodError:
       undefined method `render' for RablRails:Module

I compared the source-code and found that in v 0.4.3 RablRails::Renderer module exists, however in 0.5.0 tree it is removed

Found this commit 12a3f0f in which RablRails::Renderer module was removed.

Since that is removed what is the alternate approach to render the object directly? We are using this same approach of rendering the object directly across our API-only application. So it is very critical that we need this behaviour to be available.

Note: Ours API application is built on Rails but not using rails built-in api-only features.

Please suggest the possible fixes for this removed behaviour.

@jiggneshhgohel jiggneshhgohel changed the title Upgrading to 0.5.0 from 0.4.3 encountering "undefined method `render' for RablRails:Module Upgrading to 0.5.0 from 0.4.3 encountering error "undefined method `render' for RablRails:Module" Aug 3, 2017
@jiggneshhgohel
Copy link
Author

@ccocchi can you please spare some time and provide your guidance on my problem above?

@nimashariatian
Copy link

+1 on this issue, would appreciate a ping @ccocchi

@ccocchi
Copy link
Owner

ccocchi commented Aug 25, 2017

This module has been removed because it was trying to replicate too much ActionView internals for little gain and was poorly maintanable.

If you need the old behavior, you could try to copy https://github.com/ccocchi/rabl-rails/blob/v0.4.3/lib/rabl-rails/renderer.rb inside your application and either have RablRails extend it or call directly RablRails::Renderer.render as before.

@nimashariatian
Copy link

Thank for the update! what is new alternative to this @ccocchi :) also much appreciate the hard work

@iovis
Copy link

iovis commented Oct 16, 2019

We've been using the following instead of RablRails::Renderer.render:

ApplicationController.render(
  template: 'api/v1/users/stats',
  assigns: { user: @user }
)

@jiggneshhgohel
Copy link
Author

Using the suggestions in #88 (comment) I was able to resolve my problem I described in #88 (comment) but I needed few customizations to be made which I have detailed in https://gist.github.com/jiggneshhgohel/1f0137e5dc294cc94141785eaf836c87.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants