title: Active Model Serializers - undefined method for route helpers
body: <p>I am building a new application with the <code>rails-api</code> gem. I am using <code>active_model_serializers</code> to customize my JSON responses. In trying to add a <code>url</code> attribute to serializer, I get an error indicating that my resource's route helper methods are undefined. Pertinent code to follow:</p>
  
  <pre><code># Routes
  Rails.application.routes.draw do
    namespace :api, defaults: { format: 'json' } do
      namespace :v1 do
        resources :tasks, except: [:new, :edit]
      end
    end
  end
  
  # Controller - api/v1/tasks_controller.rb
  class Api::V1::TasksController &lt; ApplicationController
    before_action :set_task, only: [:show, :update, :destroy]
  
    # GET /tasks
    # GET /tasks.json
    def index
      @tasks = Task.all
  
      render json: @tasks
    end
  
    # GET /tasks/1
    # GET /tasks/1.json
    def show
      render json: @task
    end
  
    # POST /tasks
    # POST /tasks.json
    def create
      @task = Task.new(task_params)
  
      if @task.save
        render json: @task, status: :created, location: api_v1_task_path(@task.id)
      else
        render json: @task.errors, status: :unprocessable_entity
      end
    end
  
    # PATCH/PUT /tasks/1
    # PATCH/PUT /tasks/1.json
    def update
      @task = Task.find(params[:id])
  
      if @task.update(task_params)
        head :no_content
      else
        render json: @task.errors, status: :unprocessable_entity
      end
    end
  
    # DELETE /tasks/1
    # DELETE /tasks/1.json
    def destroy
      @task.destroy
  
      head :no_content
    end
  
    private
  
      def set_task
        @task = Task.find(params[:id])
      end
  
      def task_params
        params.require(:task).permit(:name)
      end
  end
  
  # Serializer
  class TaskSerializer &lt; ActiveModel::Serializer
    attributes :id, :name, :url
  
    def url
      api_v1_task_url(object)
    end
  end
  </code></pre>
  
  <p>As you can see, I am using namespaced routes and have the controllers working. I receive an <code>undefined method 'api_v1_task_url</code> error when I try and retrieve a task. I can't figure out why the helper methods aren't included. I'm baffled because every tutorial I find on adding custom attributes like this don't make any adjustments for using these gems (<code>rails-api</code> and <code>active_model_serializers</code>).</p>
  
  <p>Here is some more relevant information:
     rails version: 4.2.6
     rails-api version: 0.4.0
     active_model_serializers version: 0.10.0.rc5</p>
  
  <p><strong>Edit</strong>: Here is the output of <code>rake routes</code></p>
  
  <pre><code>     Prefix Verb    URI Pattern                 Controller#Action
  api_v1_tasks GET    /api/v1/tasks(.:format)     api/v1/tasks#index {:format=&gt;"json"}
               POST   /api/v1/tasks(.:format)     api/v1/tasks#create {:format=&gt;"json"}
   api_v1_task GET    /api/v1/tasks/:id(.:format) api/v1/tasks#show {:format=&gt;"json"}
               PATCH  /api/v1/tasks/:id(.:format) api/v1/tasks#update {:format=&gt;"json"}
               PUT    /api/v1/tasks/:id(.:format) api/v1/tasks#update {:format=&gt;"json"}
               DELETE /api/v1/tasks/:id(.:format) api/v1/tasks#destroy {:format=&gt;"json"}
  </code></pre>
  
  <p><strong>Edit 2:</strong> Following the suggestion below, I tried:</p>
  
  <pre><code># Serializer
  class TaskSerializer &lt; ActiveModel::Serializer
    attributes :id, :name, :url
  
    def url
      link(:self) { api_v1_task_url(object) }
    end
  end
  </code></pre>
  
  <p>And received a <code>undefined method 'link'</code> error.</p>
  
  <p><strong>Edit 3:</strong> @beauby did point out I was using this method in the incorrect place, however using it correctly still does not create an attribute via a serializer method as I've seen work in numerous tutorials such as this one: <a href="http://railscasts.com/episodes/409-active-model-serializers?view=asciicast" rel="nofollow">http://railscasts.com/episodes/409-active-model-serializers?view=asciicast</a>. It creates a <code>links</code> property following the JSONAPI schema, which while helpful and something I will remember, is not what I am trying to accomplish.</p>