Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:39:47+00:00 2026-06-15T09:39:47+00:00

I have a form to create adverts. Controllers: def edit @engines = Engine.all @car

  • 0

I have a form to create adverts.

Controllers:

  def edit
    @engines = Engine.all
    @car = Car.find(params[:id])
  end

  def update
    @car = Car.find(params[:id])

    if @car.save
      redirect_to root_path
    end
  end

My routes:

resources :adverts

Create.html.erb

<%= form_for @car, :url => adverts_path do |f| %>

  <div><%= f.label :name %><br />
  <%= f.text_field :name %></div>

  <%= hidden_field_tag :model_id, params[:model_id] %>

  <%= select_tag :engine_id, options_from_collection_for_select(@engines, "id", "name",:selected=>@car.engine_id) %>

  <div><%= f.submit "Create car!" %></div>
<% end %>

I can create advert, but I can’t to update it.

edit.html.erb

<%= form_for @car, :url => adverts_path do |f| %>

  <div><%= f.label :name %><br />
  <%= f.text_field :name %></div>

  <%= hidden_field_tag :model_id, params[:model_id] %>

  <%= select_tag :engine_id, options_from_collection_for_select(@engines, "id", "name",:selected=>@car.engine_id) %>

  <div><%= f.submit "Update car!" %></div>
<% end %>

when I submited my form, I have an error – No route matches [PUT] “/adverts”

$ rake routes:

                       adverts GET    /adverts(.:format)                     adverts#index
                               POST   /adverts(.:format)                     adverts#create
                    new_advert GET    /adverts/new(.:format)                 adverts#new
                   edit_advert GET    /adverts/:id/edit(.:format)            adverts#edit
                        advert GET    /adverts/:id(.:format)                 adverts#show
                               PUT    /adverts/:id(.:format)                 adverts#update
                               DELETE /adverts/:id(.:format)                 adverts#destroy

I need help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:39:48+00:00Added an answer on June 15, 2026 at 9:39 am

    When you are updating you have to let Rails know which object you want to update by passing an id.

    In edit.html.erb change:

    <%= form_for @car, :url => adverts_path do |f| %>
    

    to:

    <%= form_for @car, :url => advert_path(@car) do |f| %>
    

    By the way, I find your code very strange. Why don’t your model names match your controllers and routes? I mean you are creating an advert but your model is called car. That doesn’t make any sense. Either call it car or advert, but don’t mix them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form for create/edit articles. Every article is associated with an user.
I'm faced with the following problem in rails. I have a form to edit/create
I have a dialog form. <div id=dialog-form title=Create new Admin> <p class=validateTips>All form fields
I have a form. In that form I create an instance of a class
I have a form which I create manually (a lot of JavaScript in it...).
i have create a form (so it's PHP and HTML hybrid-code). it has ability
I have a form on a page that a user can use to create
I have this form with a date input. echo $this->Form->create('Nodata'); echo $this->Form->input('date1', array('type' =>
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have been tasked to create a form designer application in Windows Forms. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.