Head first rails Mebay application

51 views
Skip to first unread message

Priya Mohan

unread,
Sep 4, 2015, 1:24:02 AM9/4/15
to Ruby on Rails: Talk
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

 <html>
   
<head>
     
<title> </title>
   
</head>
   
<body>
   
<p>
     
<b>Name:</b><%= @ad.name %>
   
</p>
   
<p>
     
<b>Description:</b><%= @ad.description %>
   
</p>
   
<p>
     
<b>Price:</b><%= @ad.price %>
   
</p>
   
<p>
     
<b>Seller Id:</b><%= @ad.seller_id %>
   
</p>
   
<p>
     
<b>Email:</b><%= @ad.email %>
   
</p>
   
<p>
     <img src="
<%= @ad.img_url %>"/>
   
</p>
   
</body>
   
</html>



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



8. index.html.erb
<h1>All ads</h1>
<ul>
 
<% for ad in @ads %>
 
<li><a href ="/ads/<%= ad.id %>"><%= ad.name %></a></li>
 
<% end %>
</ul>



after starting the rails server 

in browser I am trying


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.

Priya Mohan

unread,
Sep 4, 2015, 1:24:04 AM9/4/15
to Ruby on Rails: Talk

Colin Law

unread,
Sep 4, 2015, 2:22:40 AM9/4/15
to Ruby on Rails: Talk
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

tamouse pontiki

unread,
Sep 6, 2015, 10:00:52 AM9/6/15
to rubyonra...@googlegroups.com
On Fri, Sep 4, 2015 at 1:21 AM, Colin Law <cla...@gmail.com> wrote:
On 3 September 2015 at 21:56, Priya Mohan <mmpr...@gmail.com> 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
 

Colin Law

unread,
Sep 7, 2015, 3:41:00 PM9/7/15
to Ruby on Rails: Talk
On 6 September 2015 at 15:00, tamouse pontiki <tamous...@gmail.com> wrote:
>
> On Fri, Sep 4, 2015 at 1:21 AM, Colin Law <cla...@gmail.com> wrote:
>>
>> On 3 September 2015 at 21:56, Priya Mohan <mmpr...@gmail.com> 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

That's true, perhaps I need to work through the tutorial again myself :)

Colin

tamouse pontiki

unread,
Sep 8, 2015, 11:15:54 PM9/8/15
to rubyonra...@googlegroups.com
I have the guides, the api docs, and Ruby's Enumerable pinned in my browser for re-reading. :)
 
Reply all
Reply to author
Forward
0 new messages