Search code examples
ruby-on-railsdevisehaml

HAML - how to create links so that they go to the right controllers?


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
    end
  end

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|

    end
  end

  def create

  end

  def destroy

  end
end

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.


Solution

  • 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