Routing and form problem

Have routes as: ActionController::Routing::Routes.draw do |map|   map.resources :allocations   map.resources :companies, :has_many => :notes, :shallow => true   map.resources :notes, :only => [:index]   map.suppliers 'suppliers', :controller => "companies", :action => "indexs"   map.clients 'clients', :controller => "allocations"

  # /companies/:1/allocations   map.allocations 'companies/:id/allocations', :controller => "allocations", :action => "show"   map.allocations 'companies/:id/allocations/new', :controller => "allocations", :action => "new"

  map.namespace :admin do |admin|     admin.resources :users, :roles, :assignments   end

  map.login "login", :controller => "user_sessions", :action => "new"   map.logout "logout", :controller => "user_sessions", :action => "destroy"

  map.resources :user_sessions   map.resources :admin_users   map.resources :admin_roles   map.resources :welcomes   map.resources :users   map.resources :messages   map.resources :companies   map.resources :contacts   map.resources :focs   map.resources :tops   map.resources :products   map.resources :tocs

  map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format' end

I have a page /allocations/new: <h1>Allocations for: <%= @company.name %></h1>

<table class="users" border="0" cellpadding="5" cellspacing="1">   <tr class="header">     <th>Product</th>     <th>Quantity</th>   </tr>   <% for allocation in @company.allocations %>     <tr>       <td><%=h allocation.allocated_product.name %></td>       <td><%=h allocation.quantity %></td>     </tr>   <% end %> </table> <br>

  <p> <% form_for :allocation, :url => allocations_path do |f| %>   <%= f.hidden_field :company_id, :value => @company.id %>   <%= f.collection_select(:allocated_product_id, Product.find(:all), :id, :name, :include_blank => false) %>   <%= f.label :quantity %><%= f.text_field :quantity %>   <p><%= submit_tag "Create Allocation" %></p> <% end %>

When submitting I cannot get the "create" action:   Parameters: {"commit"=>"Create Allocation", "action"=>"new", "authenticity_token"=>"zpScMwZRZix3Ube1aTbQJplv+ZI0KXpskD7xB4yOo3g=", "id"=>"1", "allocation"=>{"quantity"=>"34", "allocated_product_id"=>"2", "company_id"=>"1"}, "controller"=>"allocations"}

I think this is a very silly issue but its making me go in circles: I have noted that I dont have a POST method in the named routes "Allocations", has this anything to do with it?

I have tried to mess with the Class HTML when submitting the form but cant get it to run.

My controller looks as such:   def new     @company = Company.find(params[:id])     @allocation = Allocation.new   end

  def create     @allocation = Allocation.new(params[:allocations])     if @allocations.save       flash[:notice] = "Successfully created allocations."       redirect_to new_allocation_path(:company_id)     else       render :action => 'new'     end   end

I'm not sure what version of Rails you're using, looking at your routes file I'm guessing Rails 2.

You can check if your route exists by entering "rake routes" on the command line, if your POST route isn't in there is a problem in your routes file.

I think it's more likely that the problem is in your form though, you have:

<% form_for :allocation, :url => allocations_path do |f| %>

Try changing it to:

<% form_for @allocation do |f| %>

You can find the documentation for form_for in Rails 2.3.8 here: http://api.rubyonrails.org/v2.3.8/classes/ActionView/Helpers/FormHelper.html#M002270