Take the 2-minute tour ×

I have some links that I am trying to make work in HAML

  =link_to("My Disclosures", "") << ' |'
  =link_to("Create Disclosure", "#") << ' |'
  =link_to("My Programs", "#") << ' |'
  =link_to("Log Out", "sign_out")

What I am not sure how to do is link to different controller actions that I have.

Here are my routes:

scope :module => :mobile, :as => :mobile do
    constraints(:subdomain => /m/) do
      devise_for :users, :path => "", :path_names =>
               { :sign_in => "login", :sign_out => "logout",
                 :sign_up => "signup" },
                 :controllers => {:sessions => "mobile/sessions"}

      resources :home

      resources :disclosures # Will have new, get, look up a disclosure

So I thought my log_out path would have worked, but it isn't working it seems.

Also, I have this very simple controller:

class Mobile::DisclosuresController < ApplicationController

  def new
    Rails.logger.debug "-"*100
    Rails.logger.debug session.inspect
    Rails.logger.debug "-"*100

    respond_to do |format|


  def create


  def destroy


But I am not sure how to make the HAML links so that they lead to the various controller actions I need to go to on get and post. Any help with how to correctly link to the controllers would be much appreciated!


share|improve this question
Have you had a look at the Rails Guides on routing? –  Andrew Marshall Apr 20 '12 at 16:56
add comment

1 Answer

up vote 2 down vote accepted

Use rake routes to get a list of all your routes, including their names. Use those names and append "_path" to get the path to that route.

You should be able to disclosures like this:

=link_to "My Disclosures", disclosures_path
share|improve this answer
hi, I looked at the rake routes result, but for some reason I wasn't able to link with those routes and I thought there was some issue with the HAML. –  GeekedOut Apr 20 '12 at 17:09
what error do you get? Does the page render? Does it do the wrong thing when you click on the link? –  Larsenal Apr 20 '12 at 17:10
when I click on the log out link it just goes to a screen which is all white. –  GeekedOut Apr 20 '12 at 17:12
As an example I have a route like this: mobile_disclosures GET /disclosures(.:format) {:subdomain=>/m/, :action=>"index", :controller=>"mobile/disclosures"} –  GeekedOut Apr 20 '12 at 17:18
Should the HAML link to it be =link_to("My Disclosures", "mobile_disclosures") ? –  GeekedOut Apr 20 '12 at 17:18
show 2 more comments

Your Answer


