Spencer Hire
Spencer Hire

Reputation: 763

Rails routes generation

Hi I'm trying to just configure my routes in my rails, but it keeps on coming up with a "." instead of the traditional "/" divider in the URL, like so: localhost3000/media.1?

routes.rb

 Mediastuff::Application.routes.draw do

  get "media" => "media#index"
  get "media/:id" => "media#show", as: "media_show"


end

Media controller.

    class MediaController < ApplicationController

    def index
        @medias = Media.all
    end

    def show
        @media = Media.find(params[:id])
    end

end

index.html.erb.

<header>
  <h2><%= link_to(media.title, media_path(media)) %></h2>
</header>
<p>

Upvotes: 0

Views: 88

Answers (3)

Richard Peck
Richard Peck

Reputation: 76774

You'd be better doing this:

#config/routes.rb
resources :media, only: [:show, :index]

...and then using Uandl's answer

Upvotes: 2

Hardik
Hardik

Reputation: 3895

Because you have written as in your root then your path helper is changed get "media/:id" => "media#show", as: "media_show"

so use following:

<header>
  <h2><%= link_to(media.title, media_show_path(media)) %></h2>
</header>
<p>

Upvotes: 2

opticon
opticon

Reputation: 3594

Try <%= link_to(media.title, media_show_path(media)) %>, or just <%= link_to(media.title, media) %>.

Upvotes: 1

Related Questions