kdweber89
kdweber89

Reputation: 2174

Rails routing bug

I feel a little sheepish for asking, but i am having trouble getting a simple rails route to properly work.

Really all I created was a simple view page, but i am having trouble routing to that view page. (It has been quite a while sine i've done something like this)

My controller just has

def bio
end

my routes file is

Rails.application.routes.draw do
  root 'home#index'
  get '/bio' => 'home#bio'
end

And my view is here:

.col-sm-2.text-center
  =link_to bio_path
  %h3 bio

With what I have right now, the view that I am trying to route towards =link_to bio_path is linking straight to my home page instead. Could anybody take a quick look at this for me?

I would be very grateful.

Upvotes: 1

Views: 37

Answers (2)

Frederick John
Frederick John

Reputation: 527

You aren't including enough information in your question - can you include the error you are receiving? You should have a "home" controller which looks as such:

class HomeController < ApplicationController
  def bio
  end
end

In your routes you declare a route to the bio action in your home controller:

  get 'bio' => 'home#bio'

In your views, you should have a "home" folder with a view titled "bio". Then when you navigate to localhost:3000/bio you should see your bio.html.erb or .haml view.

Upvotes: 0

Mark
Mark

Reputation: 10988

change what you have to:

get '/bio', to: 'home#bio', as: 'whatever_bio'

Now you can say:

link_to "my link!", whatever_bio_path

Also, type rake routes in your console to get a listing of all the routes in your application. You can sift through the routes to see where bio_path routes to, and if you can't figure it out then update your answer with the results of rake routes.

Upvotes: 2

Related Questions