Questions tagged [respond-to]
112 questions
0
votes
1 answer
Using multiple arguments for a json response controller action
In my search controller I'm using a json render call for site search. I now need to pass a custom instance method to a JS file. The problem is, when I try to comma separate the necessary method (to_json) I'm getting this error in my…

Carl Edwards
- 13,826
- 11
- 57
- 119
0
votes
2 answers
How does `respond_to` function in rails work?
This is the default Rails code generated. I understand what the code does (from the explanation in the documentation) but not how it does.
1 class PostsController < ApplicationController
2 # GET /posts
3 # GET /posts.json
4 def index
…

balki
- 26,394
- 30
- 105
- 151
0
votes
2 answers
how to DRY a respond_to that is the same in all actions?
I have a controller that will server widgets:
class WidgetsController < ApplicationController
def widget1
respond_to do |format|
format.html
format.js { render js: js_constructor }
end
end
def widget2
respond_to do…

gabrielhilal
- 10,660
- 6
- 54
- 81
0
votes
3 answers
Trying to alias old method and create new one in ruby
I'm using the following snippet to only alias the method if the method exists:
alias_method old_name, func_name if self.respond_to? func_name
How can it Error with alias_method': undefined method 'get' for class 'Sinatra::Base' (NameError) when…

Thermatix
- 2,757
- 21
- 51
0
votes
2 answers
cancel default controller action's redirect
There's this link:
= link_to "Close", close_ticket_path(:id => ticket.id), :onclick => $(this).closest('tr').remove()", :remote => true
which routes to tickets_controller#close:
def close
@ticket =…

medik
- 1,174
- 12
- 17
0
votes
1 answer
Why is the proper "respond_to" format not getting called?
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:
…

humble_coder
- 2,777
- 7
- 34
- 46
0
votes
1 answer
respond.js with bootstrap 3 and IE8
In Inernet Explorer 8 Can someone please tell me why the column width on the services page are shorter than what they should be? They should be similiar to the yellow highlighted area below:
I tried viewing it in Browser Stack and using Emulation…

J86
- 14,345
- 47
- 130
- 228
0
votes
1 answer
Batch looking up on website and take action
Is there a way to create a batch file that when it looks something up on a website, and find a picture, text or something there, that it takes action to it, like, when it found the pictures the batch should GOTO:Choice1 and when not GOTO:Choice2 ?

tanckom
- 23
- 4
0
votes
1 answer
How do I change compass break points? when using respond-to mixin
I am using compass and sass (scss) to create CSS files. I believe the tablet breakpoint is too wide. The first breakpoint for my mobile-first website begins around 700px.
How do change the tablet breakpoint to be 360px? (ish)
// breakpoint is…

scottgemmell
- 159
- 1
- 1
- 9
0
votes
4 answers
Flash[:notice] if page.blank?
I am having a search form on my index page that redirects to a page that shows all statuses with the params given by search. Now I want to put in a flash notice if the page is blank because the search param doesn't fit to any of my statuses. any…

user3079933
- 63
- 1
- 9
0
votes
3 answers
At the controller level, how to prevent an anonymous user from posting?
The following is a standard posts#create action (app/controllers/posts_controller.rb).
At the controller level, I want to prevent an anonymous user (a user who is not signed in) from being able to save a post. As a secondary objective, I don't even…

user664833
- 18,397
- 19
- 91
- 140
0
votes
2 answers
Does Rails 4 allow ruby code in a .JS view, in rails 3 it was required to have .erb.js in the filename
Does Rails 4 allow ruby code in a .JS view, in rails 3 it was required to have .erb.js in the filename
def test
respond_to do |format|
format.js { Rails.logger.info "in JS handler" }
end
end
/app/views/users/test.erb.js <== no…

Rubytastic
- 15,001
- 18
- 87
- 175
0
votes
2 answers
DRYing up respond_to code in Rails
I have several actions (lets call them action_a, action_b, etc.)
In each action I want to check if the user is logged in and if not to have a respond_to block as follows
format.js {
if current_user.nil?
render partial:…

Nick Ginanto
- 31,090
- 47
- 134
- 244
0
votes
1 answer
Ruby (try_if)_respond_to. Does it exist?
I'm trying to find a shorthand method for doing the following:
if row.respond_to?(:to_varbind_list)
result << row.to_varbind_list.to_hash
else
result << row.to_hash
end
And achieve it with something like…

Oktav
- 2,143
- 2
- 20
- 33
0
votes
2 answers
How to globally PREVENT json rendering in rails?
I have a rails application in which most of the actions respond to json.
Is there any "switch" I can turn off to prevent all the controllers from responding to json despite the respond_to method call, or I still have to disable it manually in every…

Tamer Shlash
- 9,314
- 5
- 44
- 82