Questions tagged [respond-with]
51 questions
4
votes
2 answers
Rails 3: respond_with and Completed 406 Not Acceptable
I am building an API for a Rails app. I actually have two apps: a server (the API) and a client (interacting with the API). I am trying to do a post request to create a model object via an API call. When the object is valid, the model object is…

Robert Audi
- 8,019
- 9
- 45
- 67
3
votes
1 answer
Working with and Testing Rails ActionController's respond_with
Apologies in advance for the verbosity of this question. If you bear with me I think you'll find it's actually quite simple...just hard for me to explain given my limited Rails domain knowledge.
Given this comment in an ActionController commit…

Meltemi
- 37,979
- 50
- 195
- 293
3
votes
2 answers
Using respond_with to serve 404?
I'm trying to serve up a custom 404 response in rails, but I'm not sure how to give the :status to a respond_with function.
I know with render, I can do something like this:
render :status => :not_found, :json => {:response =>"There weren't any…

RileyE
- 10,874
- 13
- 63
- 106
3
votes
1 answer
respond_to causes undefined method `to_sym' for [:json, :html]:Array
In Rails 3.2.8 in Ruby 1.9.3p194 when passing an array to respond_to in an included block of an ActiveSupport::Concern that is included on demand in the class definition by calling an acts_as_... method in module included in a gem results in…

Gary S. Weaver
- 7,966
- 4
- 37
- 61
2
votes
0 answers
Specify flash in respond_with
Rails 3 has a nice feature to save writing flashes on a separate line:
redirect_to @product, :notice => "Successfully created product."
It would be great with respond_with, but not supported. Any way to override respond_with to take an optional…

mahemoff
- 44,526
- 36
- 160
- 222
2
votes
1 answer
Shortening up respond_with( :include => xxx)
I'm looking for a way to shorten up the :include => :child inside a respond_with which generates json.
Here is an example, not sure if it is even possible, but I would like to find out.
In the controller:
@p = Parent.where('id = ?',…

ThaDick
- 193
- 2
- 11
2
votes
5 answers
Rails 3 respond_with json question
Having trouble with generating some json. I am trying to render an
single active record result to json like this:
@data = User.find(1)
respond_with(@data, :include => :status)
The json result is:
{
-user: {
address: null
email:…

Mike Jaffe
- 562
- 2
- 5
- 13
2
votes
2 answers
Rails controller processing as HTML instead of XML
I've recently upgraded from Ruby 1.8.6 and Rails 2.3.4 to Ruby 1.9 and Rails 3.0.3.
I have the following controller:
class ChartController < ApplicationController
before_filter :login_required
respond_to :html, :xml
def load_progress
…

Andy
- 1,801
- 3
- 22
- 33
2
votes
1 answer
Including multiple associations using respond_with
I have a rails 3 app running on ruby v. 1.9.3 with a user, post and role model. A user has many posts as well as roles.
My routes.rb file look like this:
namespace :api, defaults: {format: 'json'} do
resources :users do
resources :posts
…

jonik
- 97
- 6
2
votes
1 answer
respond_with/to rendering wrong view
I'm trying to understand why respond_with/to is rendering the wrong view...
controller
respond_to :html, :js
def get_numbers
Rails.logger.info request.format
@numbers = Number.all
respond_with @numbers
end
when making an ajax request, the…

brewster
- 4,342
- 6
- 45
- 67
1
vote
1 answer
Rails: respond_with RESTful controller template after non-RESTful action
Getting "Template is missing - Missing template ballots/submission" error when trying to add a "publish" action to an otherwise RESTful controller. Clearly it is looking for a submission.html.haml view, which doesn't exist (and shouldn't).
class…

Meltemi
- 37,979
- 50
- 195
- 293
1
vote
2 answers
respond_with do not redirect to index.html.erb
I need help with the responder respond_with, 'cause when I create a new post (in this case) It doesn't redirect to the location specified. What can be?. This is the piece of my code that creates a new post but It's be redirected to create.html.erb…

Dagosi
- 948
- 2
- 11
- 25
1
vote
3 answers
How to convert this respond_to options to use Rails 3 version?
respond_to do |format|
if @user.save
format.js { render :nothing => true, :status => :ok, :location => @user }
else
format.js { render :json => @user.errors, :status => :unprocessable_entity }
end
end
All options I've tried (like…

Jacob
- 6,317
- 10
- 40
- 58
1
vote
2 answers
respond_with is redirecting to specified location even on validation errors, in rails3
When using location in respond with, it is ignoring validation errors and redirecting to the specified location. Is this expected behavior?
I checked in the responder module that it checking if there are any errors on the model. I inspected the…

chetu
- 245
- 3
- 15
1
vote
1 answer
In a Rails view how do I reference the object passed to respond_with in the controller?
Say I have the following:
class ProjectsController < ApplicationController
responds_to :html
def show
@project = Project.find(params[:id])
respond_with(@project)
end
end
class UsersController < ApplicationController
responds_to…

robertwbradford
- 6,181
- 9
- 36
- 61