Displaying 20 results from an estimated 22 matches for "respond_with".
2011 Jan 11
9
Can I omit respond_with.
If I don''t want xml results but only html can I omit respond_with in
some actions?
For example index from:
respond_with(@sectors = Sector.all)
becomes only
@sectors = Sector.all
isn''t it?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-...
2013 May 23
1
problem of respond_with working on nested resources
hi all:
when using namespace or nested resources in routes.rb,such as
"namespace :admin { resources :books }, we can use [:admin,@book] way to
generate path. It works fine in form_for , but when I use it with
respond_with in controller, I get problems.
The problem is when I put following code in controller:
def create
@book=Book.find(params[:id])
@book.save
respond_with[:admin,@book]
end
if there are some problems and the @book is not saved, the function
sh...
2012 Sep 18
4
"best practices" for Rails serving RESTful JSON services for use by AngularJS, Ember.js, etc.
...es not define JSON view.
* roar-rails - provides a way to specify both the JSON view and what is
accepted, so we are attempting to integrate it currently.
Where complication rears its ugly head:
When you see things like this, it looks easy:
def index
@companies = Company.all
respond_with @companies
end
But respond_with makes assumptions about what should be called, and then
you should handle errors because it should try to return those as JSON with
an appropriate HTTP status code (:ok, :unprocessable_entity, :created,
:forbidden, :internal_server_error, etc.), then there is...
2010 Nov 21
0
api respond_with json
Hello,
So let say I created this class with the following method that responds
to xml or json.
class UsersController < ApplicationController::Base
respond_to :html, :xml, :json
def index
respond_with(@users = User.all)
end
def create
@user = User.create(params[:user])
respond_with(@user, :location => users_url)
end
end
How do I call the create action from another app to interact with this
user controller class?
Is their any api package I use to do the call on create or some...
2011 Sep 09
0
respond_with and ajax
Suppose I have this controller:
class SalesController < ApplicationController
respond_to ?????
def get_price
@price = Product.find(params[:product_id]).price
respond_with ?????
end
end
1) What do I specify for respond_to() so that get_price() will accept
ajax requests?
2) What do I specify for respond_with() if all I want to do is return
@price?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google G...
2011 Jan 15
3
respond_with javascript
My ajax stopped working when I switched to using respond_with. For my
Votes, I have the create action and the corresponding create.js.erb,
and respond_to :html, :js, :xml in the controller. Heres the log when
I try and create a vote:
Started POST "/stories/3-asdfasdf1111/votes" for 127.0.0.1 at Fri Jan
14 20:46:36 -0800 2011
Processing by VotesC...
2013 Sep 26
2
Login Problem
...source_params[''password''])
if (user_email.status == "Verified" || user_email.status == nil)
/// This part is fine... It allows to login.
else
flash[:notice] = "User Not Active"
respond_with({:errors => "User Not Active"}, :location =>
sign_in_path)
end
else
flash[:notice] = "Password doesn''t match"
respond_with({:errors => "Password doesn''t match"}, :location =>
sign_in_path)
en...
2010 Jun 27
0
[rspec-rails-2] conflict with view isolation and respond_with
Hey all,
For those of you interested in view isolation in controller specs, an issue has been reported with ActionController''s new respond_with method. Please take a look at http://github.com/rspec/rspec-rails/issues/103 and add comments if you have any thoughts on the matter.
Thanks,
David
2011 Aug 15
2
respond_with with templates and http status when creating an object
Hi.
When you use respond_with in a controller #create method and want to render
XML the response gets the http status 201 (Created).
But if you use a view to render this XML response_with uses the status 200
(Ok), for example when you use the gem rabl.
I cannot determine if this matter is related to Rails or rabl. If it'...
2010 Sep 05
0
Responding to a non-registered MIME type?
...ment resource I want to return
metadata if the requested format is XML or JSON. Otherwise I want to
return the attachment itself.
class AttachmentsController < ApplicationController
respond_to :xml, :json
respond_to :all, :only => :show
def show
@attachment = ...
respond_with(@attachment) do
format.any { send_file @attachment.path }
end
end
end
This doesn''t work, because #any really means any, including :xml and
:json. This doesn''t work as intended, either
respond_with(@attachment) do
format.xml
format.json...
2010 Jul 04
2
Rendering a different format in the implementation of a renderer
...ce article on implementing a custom renderer for PDF at
http://www.engineyard.com/blog/2010/render-options-in-rails-3/
I''ve tried to follow the example and I''m not sure I see how to get it to
work. If I understand things correctly, the format(s) usable in this
render call
respond_with(@resource) do |format|
format.xyz { render :xyz => ... }
end
are set to xyz. Thus templates (for actions, partials, and layouts) are
looked up based on only this format, e.g. show.xyz.erb.
This is the correct behavior, of course, but there are legitimate
reasons for wanting to override...
2011 Sep 06
8
Ajax and rails 3 UJS (jquery)
Hi, guys,
I''m in the midst of moving an app from rails 2.3.8 to rails 3.0.9.
Sadly, rails 3 no longer has javascript generators and I''m now forced
to do more javascript.
For my project, I have selected jQuery as the javascript framework for
my rails 3.0.9 app.
What I have done to have my app''s deletion link (for each item)
trigger an alert box when the deletion
2012 Apr 05
5
rspec: identical tests fails when repeated
I''m doing RSpec controller testing with CanCan authorization, and I''m
seeing something I''ve never seen in RSpec before: the same test run
twice fails on the second one. I am NOT doing before(:all) or other
things that should cause state to persist between tests:
Here''s the relevant code:
context "POST create" do
context "with user logged
2011 Jul 11
2
Can't get this Rspec test to pass
...d }
get :new, :herd_id => 1
assigns(:herd_ration).should be(mock_herd_ration)
response.should be_success
end
end
and here''s my controller method:
def new
@herd_ration = HerdRation.new
@herd = Herd.find(params[:herd_id])
if @herd
respond_with(@herd_rations, :layout=> !request.xhr?)
else
redirect_to(root_url, :notice => ''No herd selected for ration.'')
end
end
[/code]
Here''s the catch - we have this groovy little plugin that globally enforces
a model scope via a session id, in this case: s...
2010 Jul 04
1
Rails 3: ActiveRecord .include not working
...ns
default_scope order(''title'')
scope :active, where(:active => true)
end
class CategoriesController < ApplicationController
respond_to :html, :json
# GET /categories/:id
def show
@category = Category.where(:id =>
params[:id]).include(:auctions).first
respond_with(@category)
end
end
I receive the error:
undefined method `include'' for []:ActiveRecord::Relation
I have tried this on simple has_many relationships as well, and I get
nothing but this error when trying to use .include
--
You received this message because you are subscribed to the G...
2010 Aug 28
0
Rails 3 rendering XML problem
I have Rails 3 application (running Rails RC1), and I have the following
controller:
class PluginsController < ApplicationController
respond_to :html, :xml, :json
def index
@plugins = Plugin.all
respond_with(@plugins)
end
end
If I try to render http://localhost:3000/plugins it works fine, showing
me the HTML version. If I try to get http://localhost:3000/plugins.json,
it also correctly sends me the JSON response.
However if I try http://localhost:3000/plugins.xml, I get the following
error:
Templat...
2011 Feb 03
0
Correct way to exclude attributes from json serialization
...I''m using Mongoid and Rails 3, and I want to serialize one of my
mongoid documents to json for publishing via a controller, e.g.
class ReportController < ApplicationController
respond_to :json
def show
report = Report.where(:report_id => params[:id]).first
respond_with report
end
end
This works ok, but pushes out every attribute on the document
including the "internal" mongodb document id, e.g. :
{
_id: 54857324987546, // internal mongoid document id
report_field_a: 1,
report_field_b: 2,
etc
}
I would like to strip this...
2011 Mar 22
0
Error on ajax forms/links in jQuery UI tabs
...ong?
I uses rails 3.05. I''ve tried different versions of jQuery og jQuery
Ui:
----
class InnmeldingsController < ApplicationController
respond_to :js, :html
...
def destroy
@innmelding = Innmelding.find(params[:id])
@innmelding.destroy
@innmeldings = Innmelding.all
respond_with( @innmeldings, :layout => !request.xhr? )
end
...
def list
@innmeldings = Innmelding.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @innmeldings }
format.js
end
end
...
----
list.html.erb:
...
<td><%= link_to...
2013 Feb 01
0
Add a customer renderer but I get missing template
...#39;', :mpac
ActionController::Renderers.add :mpac do |mpac, options|
self.content_type ||= Mime::MPAC
self.response_body = mpac.respond_to?(:to_msgpack) ? mpac.to_msgpack : mpac
end
My controller:
class UsersController < ApplicationController
respond_to :mpac, :json
def show
respond_with({ hello: ''world'' })
end
end
And my serializer:
require ''msgpack''
module ActiveModel
module Serializers
module MPAC
extend ActiveSupport::Concern
include ActiveModel::Serialization
included do
extend ActiveModel::Naming...
2011 Jan 06
1
View specs - best practices
Howdy,
I''m trying to test some mailer views (which is no different to normal
views in terms of specs)... ran into the following problem...
In adherence to the "one expectation per ''spec''"... I''m trying to
write the following
describe "auth/mailer/signup.html.erb" do
before(:each) do
@user = Factory.build(:user)
assign(:user,