hmm now I get Only get, put, and delete requests are allowed.
This is in my routes:
map.resources :inventories do |inventory|
inventory.resources :orders
end
map.resources :orders
And this is my controller:
before_filter :login_required, :get_inventory
def new
@order = @inventory.orders.build
end
def create
@order = @inventory.orders.build(params[:order])
if @order.save
flash[:success] = 'Order created successfully'
logger.debug "order saved successfully"
redirect_to @inventory
else
logger.debug "order not saved"
render :new
end
end
def get_inventory
@inventory = Inventory.find(params[:inventory_id])
end
end
On May 6, 4:59 pm, Jens Fahnenbruck <[email protected]> wrote:
> The routes description is different in rails 2.3.5
>
> map.resources :inventories do |inventory|
> inventory.resources :orders
> end
>
> The rest should work as described.
> On Freitag, 6. Mai 2011 at 22:56, Mlle wrote:
> Oh, I should have mentioned that I'm using Rails 2.3.5. I'm not sure
>
>
>
>
>
>
>
> > if that makes a difference?
> > I'll try out what you suggested, thanks!
>
> > On May 6, 4:51 pm, Jens Fahnenbruck <[email protected]> wrote:
> > > @order = inventory.order.build(params[:order])
>
> > > should be
>
> > > @order = inventory.orders.build(params[:order])
> > > On Freitag, 6. Mai 2011 at 22:50, Jens Fahnenbruck wrote:
> > > I'm not sure if I understood you correctly. I assume you have a route
> > > like this:
>
> > > > resources :inventories do
> > > > resources :orders
> > > > end
>
> > > > If so you could use a before filter to automatically load the inventory
> > > > in your OrdersController before every action like this:
>
> > > > class OrdersController < ApplicationController
> > > > def inventory
> > > > @inventory ||= Inventory.find(params[:inventory_id])
> > > > end
> > > > before_filter :inventory
>
> > > > def new
> > > > @order = inventory.orders.build
> > > > end
>
> > > > def create
> > > > @order = inventory.order.build(params[:order])
>
> > > > if @order.save
> > > > flash[:success] = 'Order created successfully'
> > > > logger.debug " order saved successfully"
> > > > redirect_to inventory
> > > > else
> > > > logger.debug " order not saved"
> > > > render :new
> > > > end
> > > > end
> > > > end
>
> > > > As you can see I simplified your create Action, since you don't use
> > > > anything else than html in the response you can skip the `respond_to`.
> > > > `redirect_to inventory` is short for `redirect_to
> > > > inventory_path(inventory)`, and `render :new` is a shortcut for `render
> > > > :action => 'new'`.
>
> > > > I hope I could help, if not please don't hesitate to ask again.
>
> > > > Regards, Jens
> > > > On Freitag, 6. Mai 2011 at 22:29, Mlle wrote:
> > > > > def new
> > > > > @order = @inventory.orders.build
> > > > > end
>
> > > > > def create
> > > > > @order = Order.new(params[:order])
> > > > > @order.inventory_id = params[:inventory_id]
>
> > > > > respond_to do |format|
> > > > > if @order.save
> > > > > flash[:success] = 'Order created successfully'
> > > > > logger.debug " order saved successfully"
> > > > > format.html { redirect_to
> > > > > inventory_path(@order.inventory_id) }
> > > > > else
> > > > > logger.debug " order not saved"
> > > > > format.html { render :action => "new" }
> > > > > end
> > > > > end
>
> > > > > end
>
> > > > > def get_inventory
> > > > > @inventory = Inventory.find(params[:inventory_id])
> > > > > end
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/rubyonrails-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.