respond-to

Ruby on Rails' respond_to causing strange error

瘦欲@ 提交于 2020-05-02 02:58:26
问题 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 } return end but the above code actually gave a strange error for missing template for json, and further debug leading to: respond_to do |format| format.html { render :top_page_analytics } format

respondToSelector / performSelector with parameter from a string in Swift 3

 ̄綄美尐妖づ 提交于 2020-01-05 03:37:34
问题 I have to call method of a class. This method potentially exists or not. I'm looking for a solution from 2 hours. The following works without parameter sayHello() I have the class : class myClass: NSObject { func say(something:String){ print("I say : \(something)") } func sayHello(){ print("Hello") } } 1st step : Create a selector from a string with a parameter let selector = NSSelectorFromString("sayHello" ) let selectorWithParam = NSSelectorFromString("say:" ) 2nd step : Test if the method

override to_xml to limit fields returned

旧时模样 提交于 2019-12-24 09:44:49
问题 using ruby 1.9.2 and rails 3, i would like to limit the fields returned when a record is accessed as json or xml (the only two formats allowed). this very useful post introduced me to respond_with and i found somewhere online that a nice way to blanket allow/deny some fields is to override as_json or to_xml for the class and set :only or :except to limit fields. example: class Widget < ActiveRecord::Base def as_json(options={}) super(:except => [:created_at, :updated_at]) end def to_xml

How to render js template from module included in controller?

China☆狼群 提交于 2019-12-22 10:38:16
问题 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 file (or any view, for that matter)? Is it a problem with my routes? The link for the module action = link_to image_tag("upvote.png"), send("vote_socionics_#{votable_name}_path", votable, vote_type: "#{s.type_two_im_raw}"), id: "vote-#{s.type_two_im

How to make a respond_to by AJAX in Rails 3?

我是研究僧i 提交于 2019-12-22 01:22:41
问题 I have a form, that I send with using AJAX. The form is in the FirstsController . I need the form send to SecondsController . The form is sent and data saved. Then I wanna change the form by a text, I try to do by this way: def create ...saving... respond_to do |format| format.js { render :update do |page|; page << "$('#id_element').html('hellllloooooo');" end } format.html {} end end And I ma getting this error: ActionView::MissingTemplate (Missing template seconds/update, application/update

How to convert this respond_to options to use Rails 3 version?

萝らか妹 提交于 2019-12-22 00:07:46
问题 respond_to do |format| if @user.save format.js { render :nothing => true, :status => :ok, :location => @user } else format.js { render :json => @user.errors, :status => :unprocessable_entity } end end All options I've tried (like putting respond_to :js at the top of controller, etc) don't quite work the way as in this. 回答1: Rails 3 Format: Use respond_to :json and respond_with (@user) respond_to :json # You can also add , :html, :xml etc. def create @user= User.new(params[:user]) #---For html

Rails 4 Devise Sessions Controller Unknown Format

戏子无情 提交于 2019-12-13 15:37:05
问题 I'm encountering this error : ActionController::UnknownFormat (ActionController::UnknownFormat): Each time i'm posting to Rails 4 Devise Sessions Api Controller. Here is the gist as well as logs, can anyone please help me with this ? https://gist.github.com/jsooriah/8574465 Best, j. 来源: https://stackoverflow.com/questions/21302165/rails-4-devise-sessions-controller-unknown-format

Rails respond_with — why does POST return a URL instead of the data?

梦想的初衷 提交于 2019-12-12 07:45:19
问题 This is a question "why does it work this way", not "how do I make this work". My app is calling a third party REST API that returns JSON, and returning the result as part of my own JSON API. I was using the Rails 3 respond_to and respond_with methods; in the case of GET requests, this works as I expect, just passing through the JSON. In the case of POST , it does more, including making a URL from the object returned to pass in a :location option. But since my object is just JSON (not

JRuby: command pattern in Java with Ruby block: why does it work?

家住魔仙堡 提交于 2019-12-08 02:06:06
问题 I am learning how to integrate Java library with Ruby code and come to the following question. I have a command pattern implemented in Java, as follows: public interface Command { public String execute(String param); } public class CommandRunner { public String run(Command cmd, String param) { return cmd.execute(param)+" [this is added by run method]"; } } When I import that to JRuby program I can implement Ruby class that respond_to? :execute with one parameter and pass it to the

How to render js template from module included in controller?

笑着哭i 提交于 2019-12-05 23:11:33
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 file (or any view, for that matter)? Is it a problem with my routes? The link for the module action = link_to image_tag("upvote.png"), send("vote_socionics_#{votable_name}_path", votable, vote_type: "#{s.type_two_im_raw}"), id: "vote-#{s.type_two_im_raw}", method: :post, remote: true ** The link for the controller action** = link_to "whatever",