respond-with

    0熱度

    1回答

    我有控制器,它使用respond_with和jbuilder來呈現一些JSON數據。 我需要在某處保存呈現的字符串。通常我可以使用render_to_string,但這需要我通過template參數和locals。 我需要的是讓使用respond_with(@object)呈現訪問字符串,例如: {"id": 1, "name": 2}並保存到某個地方 什麼想法?

    1熱度

    1回答

    一個難題的有點繞使用JSON用於更新資源respond_with 3.2.16 JSON API的行爲: 如果我使用「POST」反對/資源/:ID - 我得到一個未定義路由 如果我使用「PUT」來對付/ resource /:id - 我確實使用了正確的方法,但respond_with似乎返回一個空的內容(請參閱下面的代碼)。 https://github.com/rails/rails/blob

    0熱度

    1回答

    我使用這個第三方控制器: class LibController def update # 29 lines of code respond_with resource end end 我想要做的比respond_with在結束其他的東西。但我不想將所有29行復制/粘貼到MyController.update。可惜我不能想出一個辦法

    1熱度

    2回答

    我試圖提供一個自定義的404響應在rails中,但我不知道如何給:respond_with函數的狀態。 我知道有render,我可以做這樣的事情: render :status => :not_found, :json => {:response =>"There weren't any results"} 我怎麼可以做這樣的事情與respond_with?有沒有辦法用respond_with

    2熱度

    1回答

    多個關聯我有一個軌道上的紅寶石V上運行的應用程序3。1.9.3與用戶,後和作用模型。用戶有很多帖子和角色。 我的routes.rb文件是這樣的: namespace :api, defaults: {format: 'json'} do resources :users do resources :posts resources :roles end en

    0熱度

    1回答

    給定以下控制器。 class Posts_controller < ApplicationController def create @post = Post.new(:params[:post]) flash[:notice] = 'Post successfully saved' if @post.save respond_with(@post,

    0熱度

    1回答

    這是我在我的控制器創建方法(舊的方式): def create @athlete = Athlete.find(params[:video][:athlete_id]) @video = Video.new(params[:video]) if @athlete.can_add_another_video? && @video.save flash[:n

    3熱度

    2回答

    在控制器,我想respond_with更換if..render..else..render: # Current implementation (unwanted) def create @product = Product.create(product_params) if @product.errors.empty? render json: @product

    1熱度

    2回答

    我必須通過2個對象,以顯示所以我試圖把這個 respond_with(@ticketnfr, @ticket) ,但它去售票控制器視圖, ,當我試圖與只有一個對象 respond_with(@ticketnfr) 它去正確地ticketnfr /節目,但我錯過了車票參數,可以 我一個LSO試圖把位置 respond_with(@ticketnfr, @ticket. :location =

    0熱度

    1回答

    我重構了一些舊的代碼理解並想獲得對respond_with語法更好地把握... 這裏是我的控制器: class VideosController < ApplicationController authorize_resource before_filter :authenticate_user! respond_to :json, :js, :html