title: Ruby on Rails routes.rb not working
body: <p>I'm upgrading an existing Rails app. I want to add a new route to the routes.rb file, that links to a function in a controller. Excerpt from the original <em>working</em> routes.rb file:</p>
  
  <pre><code>match 'items/:id/add_to_collection/:collection_pid'     =&gt;  'items#add_to_collection', :via =&gt; [:get, :post]
  </code></pre>
  
  <p>Controller file:</p>
  
  <pre><code>  #add to a task
    def add_to_collection
      @item = Item.find(params[:id])
      @collection_pid = params[:collection_pid]
  
      #does the item have a RELS-EXT datastream?
      @rels_ext_ds =  RELS_EXT_Datastream.new(:id =&gt; params[:id])
      if !@rels_ext_ds.nil?
           @rels_ext_ds.add_relation("fedora:isMemberOfCollection",{"rdf:resource","info:fedora/" + @collection_pid})
           @rels_ext_ds.save_to_fedora
      end
      render :text =&gt; "OK"
   end
  </code></pre>
  
  <p>I want to add a function that does something similar, so I add to the routes.rb file:</p>
  
  <pre><code>match 'items/:id/add_to_event/:event_pid'       =&gt;  'items#add_to_event', :via =&gt; [:get, :post]
  </code></pre>
  
  <p>And to the controller file:</p>
  
  <pre><code>  #add to an event
    def add_to_event
      @item = Item.find(params[:id])
      @event_pid = params[:event_pid]
  
      #does the item have a RELS-EXT datastream?
      @rels_ext_ds =  RELS_EXT_Datastream.new(:id =&gt; params[:id])
      if !@rels_ext_ds.nil?
      @rels_ext_ds.add_relation("fedora:isMemberOfEvent",{"rdf:resource","info:fedora/" + @event_pid})
      @rels_ext_ds.save_to_fedora
      end
      render :text =&gt; "OK"
    end
  </code></pre>
  
  <p>When I run the application however (after restarting Apache), the application redirects and doesn't call the function. From the log file:</p>
  
  <pre><code>Started GET "/app/items/123456/add_to_event/testerevent" for 192.168.102.22 at Tue Apr 08 15:42:18 +0200 2014
  Processing by ItemsController#add_to_event as HTML
  Parameters: {"id"=&gt;"tcmp:123456", "event_pid"=&gt;"testerevent"}
  Redirected to https://localhost/app/login
  Completed 302 Found in 87ms
  </code></pre>
  
  <p>Do I need to restart some other service, rebuild the app somehow or clear some cache? I know my function content in the controller is 100% correct because when I replace the original function's content with the new function's content, everything works fine. I tried to print some log in my new function, but there is no log find to be found, indicating the function was never called. It seems to be matching in the log file though. Am I overlooking something here? I'm fairly new with RoR. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>I found out which function redirects my app to the login page. Is a function called check_authorization in the application_controller.rb file.</p>
  
  <pre><code>def check_authorization
    user = User.find(session['user'])
    unless user.roles.detect{|role|
      role.rights.detect{|right|
        right.action == action_name &amp;&amp; right.controller == self.class.controller_path
      }
    }
    flash[:notice] = "Please log in to access the page you requested. (action "+action_name.to_s+", controller "+self.class.controller_path.to_s+")"
    #request.env["HTTP_REFERER"] ? (redirect_to :back) : (redirect_to :controller =&gt; 'users',:action=&gt;'login') &lt;-- This function
  end
  </code></pre>
  
  <p>The weird thing is, I really am logged in.</p>