构建Rails API

时间:2015-01-13 22:36:31

标签: ruby-on-rails ruby api

我需要一些帮助来创建一个非常简单的API。只是尝试使用浏览器获取轨道上的基本信息。

这是VoicesController

class Api::V1::VoicesController < ApplicationController
  respond_to :json, :xml

   def index
     @tracks = Track.all
     respond_with json: @tracks
   end

  def show
    @track = Track.find_by(:id => params[:track_id]).users
    render json: @tracks
  end

end

这是我的路线:

Rails.application.routes.draw do

  devise_for :users
  devise_scope :user do
  authenticated :user do
  root :to => 'users#show', as: :authenticated_root
end
unauthenticated :user do
  root :to => 'devise/registrations#new', as: :unauthenticated_root
end
end

  resources :songs 

  resources :users

  resources :versions
  get 'versions/:id/download' => 'versions#download', :as => :version_download
  get 'versions/:id/make_master' => 'versions#make_master', :as => :make_master
  resources :comments

  resources :team_members

  post '/users/search' => 'users#search'

  namespace :api do
    namespace :v1 do
      get '/users' => 'users#index'
      get '/team_members/:song_id' => 'users#team_members'
      get '/versions/:id/comments' => 'comments#index'
      post '/versions/:id/comments' => 'comments#create'
      get '/voices' => 'voices#index'
    end
  end

  get '/search' => 's

我需要做些什么来使这个工作并让json显示在我的浏览器中?

0 个答案:

没有答案