I've got a Rails app returning data via JSON and XML.
In the controller, I've got something like this:
respond_to do |format|
format.xml { render :xml => @customers.to_xml(:include => [:invoices])) }
end
The Rails app returns the customers in a pretty XML doc but it always shows the 'invoices' array as empty (i.e. no data for the r...
Hello
I am trying to send send an xml Doc from an action
The XML is created by the following method
def media_xml
x = Builder::XmlMarkup.new
x.instruct!
x.declare! :DOCTYPE, :html, :PUBLIC, "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
x.options{
x.videos{
for m in self.media
x.i...
I have some saved text in my create controller. If it's not stressful, I'd like it to populate a textarea on the page with the saved text along with displaying the error message fields (which is what's already happening). I've used things like replace_html before, but I don't know if there's an easy way to get to textarea or text field I...
If I have a block of code like this:
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
How do I add something like
format.json
Any tips, pointers, ideas gladly welcomed...
...
Hi All,
I'm having a bit of an odd issue. Really too odd to type out, but here goes. Basically I have a controller that refuses to "respond_to" using javascript unless I assign my "chart.generate_xml" to a variable before the "respond_to" block like so:
@xml = @chart.generate_xml(@begin_date,@end_date,1.hour)
respond_to do |forma...
I have a controller that has if-condition:
def update
@contact_email = ContactEmail.find(params[:id])
if @contact_email.update_attributes(params[:contact_email])
flash[:notice] = "Successfully updated contact email."
redirect_to @contact_email
else
render :action => 'edit'
end
end
Where do I put ...
I know in Ruby that I can use respond_to? to check if an object has a certain method.
But, given the class, how can I check if the instance has a certain method?
Ie, something like
Foo.new.respond_to?(:bar)
But I feel like there's gotta be a better way than instantiating a new instance.
What are your suggestions? Thanks.
...
Using a case construct for type-safe casting is easily done in scala. The following code ensures that square gets only called on objects which have an according type.
class O
class A extends O {
def square(i: Int):Int = { i*i }
}
class B extends O {
def square(d: Double):Double = { d*d }
}
class C extends O {}
def square(o: O) ...
Is there a mechanism or accepted approach for responding to requests that have a more complicated format extension?
My specific scenario involves returning a plist file. However, I need to sometimes return this file as an XML plist file and sometimes as a binary plist file.
I thought that URLs composed like /resources.xml.plist and /re...
There is another respond_to for the usual case, and a special case when a param[:top] is passed in, so there is another respond_to earlier in the code:
respond_to do |format|
format.html { render :top_page_analytics }
format.json { render :json => @analytics }
format.xml { render :xml => @analytics }
...
I've a rails controller that respond_to JSON with a wrong encoding.
The site is correctly setup with UTF-8 encoding and the database as well.
The text in my db is well formatted, but in the JSON response, all special characters are set to \ufffd.
How can I solve the problem?
...
My Rails application is currently using JSON as the respond_to format for AJAX forms on the site. I'm planning to create a public API for the application, and I'd like to use JSON for it also. How might I distinguish between an AJAX form and an API call in my controllers if the requested format for both is JSON?
...