Questions tagged [respond-to]

112 questions
4
votes
1 answer

A good Example how rails respond_to work with model-validation errors and ajax form

What i want I use the new rails respond_to Controller Api with a ajax form. If an object does not validate rails returns a Json Error Object and triggers the "ajax:error" event. I want to show each error next/under the corresponding form field (we…
aka47
  • 41
  • 4
4
votes
2 answers

Django equivalent of rail respond_to

In Rails, I can use respond_to to define how the controller respond to according to the request format. in routes.rb map.connect '/profile/:action.:format', :controller => "profile_controller" in profile_controller.rb def profile @profile =…
Kelvin Tan
  • 982
  • 1
  • 12
  • 33
4
votes
1 answer

Rails Json response encoding

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…
pasine
  • 11,311
  • 10
  • 49
  • 81
4
votes
1 answer

rails controller respond_to format with two extensions (e.g. tar.gz)

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…
Bo Jeanes
  • 6,294
  • 4
  • 42
  • 39
4
votes
2 answers

Is a type-safe respond_to in scala possible?

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…
Debilski
  • 66,976
  • 12
  • 110
  • 133
4
votes
1 answer

respond_to do |format| format.js not working

What do I have to enable/install to get my respond_to block to return js? Rails 4.2.0 ruby 2.2 (Also tried with 4.0... I downgraded to match setup as work...) The console returns error: Processing by CameraController#show as HTML Completed 406 Not…
Peter Black
  • 69
  • 1
  • 9
3
votes
3 answers

respond_to with custom format aliasing json format, is this possible?

I have a situation where I'm returning json objects to my application which are built from YML files. Because to parse the yml file and return it as json I always have to do something like this: format.json { render json: YAML.load(render_to_string…
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
3
votes
2 answers

AbstractController::DoubleRenderError that shouldn't be

I've been getting the following error when I hit this destroy method in a my User controller. AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action. Please note that you may only call render OR…
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

Rails respond_to redirect not working

The respond_to block in a create controller in my Rails app is not redirecting on a successful save... I'm sure this is a simple solution, but I am inexperienced with Rails and this is the first time that I am encountering this problem. The form is…
skwidbreth
  • 7,888
  • 11
  • 58
  • 105
3
votes
1 answer

add a local variable to a respond_to render view

I currently have the following code and it works fine: respond_to do |format| format.json { render :show, status: :ok } end I believe :show is referring to a jbuilder view. However, if I wanted to add a local variable to the json render, how…
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
3
votes
2 answers

How to render js template from module included in controller?

I have an action in a controller concern, which gets included in a controller. This action does not render a js.erb file as specified under a respond_to block. How do I properly get an action in a controller concern to successfully render a js.erb…
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85
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
2 answers

Javascript not being executed from post-commit of remotipart

I'm a newb RoR programmer and I'm currently trying to make my js work after I upload a file using remotipart and submitting it with a POST request to the controller. Basically, after the button submit is clicked, the POST request is successfully…
Normz
  • 271
  • 1
  • 2
  • 9
2
votes
1 answer

How can I change the mime type of a request after I receive it?

My customers are sending my rails app requests as either XML or HTML. Under rails 2.10 my controller action had a responds_to block with wants.html and wants.xml. My customers set their HTTP headers for Content-Type=text/xml and Accept=text/xml if…
user127708
  • 56
  • 3