Head first rails Mebay application

I am using rails 3 and the steps that I have done

1.rails new MeBay

2.rails g model ad name:string description:text price:decimal
seller_id:integer email:string imr_url:string

3.rake db:migrate

4.rails generate controller ads

5.show.html.erb

Name:<%= @ad.name %>

Description:<%= @ad.description %>

Price:<%= @ad.price %>

Seller Id:<%= @ad.seller_id %>

Email:<%= @ad.email %>

6.config/routes.rb

controller ‘ads’ do
match ‘ads/:id’ => :show
match ‘ads/:id’ => :index
end

7.ads_controller
def show
@ad = Ad.find(params[:id])
end
def index
@ads = Ad.find(:all)
end

  1. index.html.erb

All ads

after starting the rails server

in browser I am trying

http://localhost:3000/MeBay
http://localhost:3000/show/ads/3

I am getting routing error. Please help on solving this error.

No route matches [GET] “/MeBay”
No route matches [GET] “/show/ads/3”

please note:other scaffolding project that I created in RoR runs well.
but
not this one. please help where I went wrong.

On 3 September 2015 at 21:56, Priya M. [email protected] wrote:

</p>
 <b>Email:</b><%= @ad.email %>

controller ‘ads’ do
@ads = Ad.find(:all)
<% end %>
I am getting routing error. Please help on solving this error.

No route matches [GET] “/MeBay”
No route matches [GET] “/show/ads/3”

please note:other scaffolding project that I created in RoR runs well. but
not this one. please help where I went wrong.

Firstly don’t use Rails 3 as it is not only obsolete but will go out
of support within a few months. As a beginner I suggest you work
right through a good tutorial (which uses the latest rails) such as
railstutorial.org (which is free to use online). That will show you
the basics or Rails.

As for your specific problem it should be /ads/show/3. Also the route
for index should not include the id. But in routes.rb you should be
using resources rather than match for such cases. As I said work
through the tutorial before going further.

Colin

On Fri, Sep 4, 2015 at 1:21 AM, Colin L. [email protected] wrote:

On 3 September 2015 at 21:56, Priya M. [email protected] wrote:

6.config/routes.rb

controller ‘ads’ do
match ‘ads/:id’ => :show
match ‘ads/:id’ => :index
end

As for your specific problem it should be /ads/show/3. Also the route
for index should not include the id. But in routes.rb you should be
using resources rather than match for such cases.

The “show” route would just be /ads/3 : http://localhost:3000/ads/3
The “index” route is just /ads: http://localhost:3000/ads

As I said work
through the tutorial before going further.

Colin

Tamara

On Mon, Sep 7, 2015 at 2:40 PM, Colin L. [email protected] wrote:

match ‘ads/:id’ => :index

That’s true, perhaps I need to work through the tutorial again myself :slight_smile:

I have the guides, the api docs, and Ruby’s Enumerable pinned in my
browser
for re-reading. :slight_smile:

On 6 September 2015 at 15:00, tamouse pontiki [email protected]
wrote:

As for your specific problem it should be /ads/show/3. Also the route
for index should not include the id. But in routes.rb you should be
using resources rather than match for such cases.

The “show” route would just be /ads/3 : http://localhost:3000/ads/3

That’s true, perhaps I need to work through the tutorial again myself :slight_smile:

Colin