Questions tagged [respond-to]
112 questions
0
votes
1 answer
Respond with script from a Rails API app with limited middleware (config.api_only = true)?
I have a Rails 5 app build as an api app. So by default it only responds with json.
But for one specific request I need the app to respond with a script.
In a regular Rails app I would simply put my script in a js.erb file. This won't work here.
If…

JohnSmith1976
- 536
- 2
- 12
- 35
0
votes
4 answers
Ruby 1.9.2 Object.respond_to? :hello && Object.hello gives error, why?
While stepping through code today, I noticed something unexpected. This statement:
if Object.respond_to? :hello && Object.hello
#stuff
gives an undefined method error. But why? Obviously hello is not a valid method of Object, however given the…

TheTFo
- 741
- 2
- 8
- 25
0
votes
2 answers
link_to remote: true redirecting to HTML
At the /tags page I have a link with remote: true. It should be a link to an ajax request. But there are two requests, as JS and as HTML.
<%= link_to 'New', new_tag_path, class: "btn btn-outline btn-primary", remote: true %>
INFO -- : Started GET…

carlos prado
- 49
- 2
- 6
0
votes
1 answer
respond_to do |format| gives "UnknownFormat in UsersController#show" in rails 5 app
In my rails 5 app I want to render partials in a div in the views/users/show.html.erb on link click.
I believe I have set things up accordingly but rails gives me this error ActionController::UnknownFormat in…

Slowboy
- 581
- 1
- 7
- 25
0
votes
1 answer
respond_to not working with format.js if format.html is present
When using respond_to, my AJAX call only invokes the javascript response if the HTML response isn't present.
I have the following javascript for submitting an edit-in-place action:
$(".eip").editable("/surveys", {
name : 'survey[name]',
select…

Shpigford
- 24,748
- 58
- 163
- 252
0
votes
2 answers
Rails3 and Respond_with problem
I have an application, on which I have two user interfaces.
The first one is for normal users and the second one is for iphone users.
Everything was working fine until i refactored my code within controller to use the respond_with declarative…

Arkan
- 6,196
- 3
- 38
- 54
0
votes
2 answers
rails respond_to in controller rescue block
respond_to not working inside controller rescue block:
def create
respond_to do | format |
format.json { render json: SomeManager.new(some_params).json }
format.html do
SomeManager.new(some_params)
render :new, notice: 'it…

xxjjnn
- 14,591
- 19
- 61
- 94
0
votes
1 answer
Too may redirects rails respond_to
I have a controller action method that gets all records of establishments from the DB, I then want to share this response with a external entity which is a RhoMobile application, i used respond_to to format the response to JSON.
def index
…

Thabo
- 1,303
- 2
- 19
- 40
0
votes
0 answers
(Rails) Remote form responds with .js on update but not on create
I have a simple remote form logic in my Rails app to respond to new, create, edit and update actions of my controller with AJAX. My form_for...remote => true responds with format.js, but not to my successful create-actions. I use the same…

R4ttlesnake
- 1,661
- 3
- 18
- 28
0
votes
1 answer
Using different logic for the same respond_to format in Rails
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…

Jimmy
- 35,686
- 13
- 80
- 98
0
votes
1 answer
ActionController::UnknownFormat with respond_to js in Action:Create
my route.rb
post 'home/create'
get 'home/create'
my HomeController
def create
@review_n = Review.create(review_params)
if @review_n.errors.empty?
respond_to do |format|
format.js { render 'create', locals:…

deni5n
- 97
- 1
- 10
0
votes
0 answers
Respond_to throwing redirect error
I have the following block which takes in two values (example amount but generally more than one).
def new
# Called when campaign is approved, respond then displays table with campaign details, which when submitted is passed to create
@campaign =…

EamonnMcElroy
- 587
- 6
- 20
0
votes
1 answer
Ruby on Rails' respond_to causing strange error
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 }
…

nonopolarity
- 146,324
- 131
- 460
- 740
0
votes
1 answer
respondsToSelector on optional delegate methods
I'm converting this Objective-C open source project to Swift. It has a bunch of optional delegates.
@protocol BEMAnalogClockDelegate
@optional
- (void)currentTimeOnClock:(BEMAnalogClockView *)clock Hours:(NSString *)hours…

Isuru
- 30,617
- 60
- 187
- 303
0
votes
1 answer
Rails 4 - scaffold generator
I am trying to make an app with Rails 4.
I have used the generate scaffold command to setup an articles controller.
It currently looks like this:
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit,…

Mel
- 2,481
- 26
- 113
- 273