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