2016-09-03 4 views
0

私はjsonとして単純なPOROを返す必要があるRails 5.0.0.1 APIアプリケーションを持っています。私はgemのレスポンダーを使用しています、 '〜> 2.3.0'rails 5 apiはPOROから301を返します

オブジェクトは正しく構築され、Railsサーバーで正しく動作します。フロントエンドが必要とする属性は4つだけです。

シリアライザは:

class WebsiteConfigSerializer < ActiveModel::Serializer 
    attributes :force_first_user_to_be_admin, :allows_delete_of_last_admin, 
       :is_private_website,   :invite_only 
end 

コントローラショー方法(コントローラ内の唯一の方法)がある:

def show 
    config = WebsiteConfig.new 
    puts "Config: #{config.to_json}" 
    respond_to do |format| 
    format.json {render(json: config, status: 200) } 
    end 
end 

ログデバッグ含む要求出力を示すステートメントを置く:

Started GET "/config.json" for 127.0.0.1 at 2016-09-03 18:23:32 -0400 
Processing by WebsiteConfigController#show as JSON 
Config: {"force_first_user_to_be_admin":true, "allows_delete_of_last_admin":false, "is_private_website":true, "invite_only":true} 
[active_model_serializers] Rendered WebsiteConfigSerializer with ActiveModelSerializers::Adapter::Attributes (0.13ms) 
Completed 200 OK in 2ms (Views: 1.2ms | ActiveRecord: 0.0ms) 

期待どおりです。

のcURLの出力は次のようになります。

curl -sb -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:3000/config 
<html> 
    <head><title>301 Moved Permanently</title></head> 
    <body bgcolor="white"> 
    <center><h1>301 Moved Permanently</h1></center> 
    <hr><center>nginx</center> 
    </body> 
</html> 

これは私が期待したものではありません。

wget出力はEMPTY(0バイト)です。私が期待したものでもない。

明らかに私は何かが不足しています。どんな助けもありがとう。

答えて

0

あなたのリクエストはリダイレクトされました。ログインなどの認証コードがあるかどうかを確認してから、curlコマンドに追加してください。

関連する問題