Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to create a simple form in Rails 3. But facing this issue:

Showing /home/praveen/rails_projects/mebay/app/views/ads/new.html.erb where line #2 raised:

No route matches {:action=>"create", :new=>"new", :controller=>"ads"}

 <h1> New Ad</h1>
 <% form_for @ad, url:{action: "create"} do |f| %>
 <p>
 <b>Name</b>
 <%= f.text_field :name %>

I am a beginner in Rails but as per my understanding , there is some problems in the config/route.rb ..

I have declared following routes in this file...

get 'ads/:new'=>'ads#new'
get 'ads/:create'=>'ads#create'
get 'ads/'=>'ads#index'
get 'ads/:id'=>'ads#show'

Last is the controller file where i have declared my functions:

class AdsController < ApplicationController
def new
    @ad=Ad.new
end

Let me know if some more information is required.

share|improve this question
add comment

1 Answer

Hey @Praveenks if you're a beginner in rails, I would recommend you to use the scaffold generator.

rails generate scaffold ads attribute1:type attribute2:type...

In this way rails generates for you the controller, views and routes for your Ads model.

By the way, to create the routes you want to, try the follow in your routes.rb file:

resources :ads, only: [:new, :create, :index, :show]

I hope it helps :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.