Questions tagged [responders]
21 questions
11
votes
1 answer
How to respond_to PNG or JPG in Rails and generate image from HTML?
I am looking for a gem or solution to generate image in controller response.
It would be nice if it's possible to do in controller like that:
respond_to :html, :png
def show
...
respond_to do |format|
format.html
format.png { ??? } #…

Voldy
- 12,829
- 8
- 51
- 67
8
votes
2 answers
Including nested objects in JSON response, from MongoMapper objects
class Api::StoresController < ApplicationController
respond_to :json
def index
@stores = Store.all(:include => :products)
respond_with @stores
end
end
Returns only stores without their products, as does…

oliverbarnes
- 2,111
- 1
- 20
- 31
5
votes
2 answers
How to customize the JSON that respond_with renders in case of validation errors?
In a controller, I want to replace if..render..else..render with respond_with:
# Current implementation (unwanted)
def create
@product = Product.create(product_params)
if @product.errors.empty?
render json: @product
else
render json: {…

João Souza
- 4,032
- 3
- 25
- 38
4
votes
1 answer
Responders gem: add a model's base errors to the flash message?
Is there an easy way to add a model's base errors to the flash message in the responders gem?
When I try to delete a record with depending children that has dependent: :restrict_with_error set, then I see an error like "X could not be destroyed",…

Joshua Muheim
- 12,617
- 9
- 76
- 152
2
votes
2 answers
Where should custom Responders go in a Rails project?
I need to implement a custom Responder under "Module Responders", however, I am not sure where such code should live?
user427165
2
votes
1 answer
respond_with having issue with Rails 5
I am upgrading my Rails app from 4.1.1 to 5.1.4.
I am using roar-rails gem to parsing and rendering REST documents. I am facing some issues as responders gem has been extracted to separate gem.
respond_with has been moved to 'responders' gem.
My…

RoR developer
- 61
- 1
- 7
2
votes
0 answers
Edit view still shows after rescuing from Pundit::NotAuthorizedError and redirecting
I have a pretty standard setup: Identity::Member are users, and each Project::Project is owned by a member. I use Devise and Pundit together for authentication and authorization.
Here's my code for Project::ProjectPolicy
class Project::ProjectPolicy…

Dovizu
- 405
- 3
- 13
1
vote
2 answers
Using responders with a respond_with that takes a block
I was running rails 3.2.1 and using rails 3 responders as well as the flash responder available in the responders gem: https://github.com/plataformatec/responders
For some of my controller actions I always want to redirect back to the previous URL…

Mario Visic
- 2,653
- 1
- 22
- 29
1
vote
0 answers
Rails; Autoload issue after installing Sidekiq: ArgumentError (A copy of Api::V1 has been removed from the module tree but is still active!):
I have a rails (v5.1) project in development, in which I recently installed Sidekiq. I now have an autoload issue, getting the subject argument error.
I have done a fair bit of research which seem to boil down to this being a problem of "trying to…

bigmugcup
- 1,321
- 4
- 15
- 26
1
vote
2 answers
Set layout from responder?
I am trying to figure out how to set the layout from a custom made responder. I want to use the request.xhr? to set the layout for render to 'ajax'. Does anybody know how to do that?
I am using Rails 3 and I have a responder like this:
module…

demersus
- 1,185
- 2
- 10
- 24
1
vote
1 answer
Rails: respond_with custom object
respond_with is acatually meant to use with ActiveModel's instances. I tried to use it with OpenStruct's instance, but it raises an error.
Is that ever possible to use respond_with with custom objects?
class CryptController < ApplicationController
…

DreamWalker
- 1,327
- 1
- 11
- 19
1
vote
2 answers
Overriding the JSON response of respond_with for errors
I want to customize the error response of respond_with. The way it renders errors is like this:
# /app/controllers/articles_controller.rb
def create
article = Article.new(params[:article])
article.save
respond_with(article)
end
Response:
{
…

you786
- 3,659
- 5
- 48
- 74
1
vote
1 answer
Rails I18n changes apostrophe to ASCII
I'm using responders gem, and I want to show validation errors when form is not valid. In my controller I created the interpolation_action
def interpolation_options
{ resource_errors: @project_user.errors.full_messages.join(', ') }
end
and my…

Dawid
- 644
- 1
- 14
- 30
1
vote
1 answer
Rails and respond_with: why are the status codes not right?
I'm trying to use bare bones rails controllers and have a more fine-grained control at the same time. If I'm on :new action, I respond_with my new @instance and I get a status code 200 and render the :new template. On show, same thing, different…

ChuckE
- 5,610
- 4
- 31
- 59
0
votes
1 answer
Getting "undefined method `flash`" for my controllers after updating Rails from 4.1 to 5.2 and added the responders gem
I'm in the process of updating rails from 4.1 to 5.2
I added the responders gem so respond_with is present.
My ApplicationController now looks like this:
class ApplicationController < ActionController::API
self.responder = ApplicationResponder
…

Im_Matt_Murdock
- 27
- 1
- 7