user1946705
user1946705

Reputation: 2888

Rails 3 - how to se an URL, where the form will be send

I would like to ask, if is some rule for action, where is the form send... If I have a in controller

  def edit
    @shop = Shop.find(params[:id])
  end

View:

<%= form_for(@shop, :html => {:multipart => true}) do |f| %>

So in HTML source is:

<form accept-charset="UTF-8" action="/shops/11" class="edit_shop" enctype="multipart/form-data" id="edit_shop_11" method="post">

And this mean, this form will be send on :controller => 'shops', :action => 'update'.

And I am trying to change this action, where will be form send. I tried something like this:

<%= form_for(@shop, :url => {:controller => 'shops', :id => params[:id], :action => 'aupdate'}, :html => {:multipart => true}) do |f| %>

But in HTML source is

<form accept-charset="UTF-8" action="/shops/aupdate?id=11" class="edit_shop" enctype="multipart/form-data" id="edit_shop_11" method="post">

I would like to ask - how is possible, the form is not send on the action update in this case? And what would be needed to do for it?

Thank you

Upvotes: 0

Views: 784

Answers (1)

Muhammad Sannan Khalid
Muhammad Sannan Khalid

Reputation: 3137

in your view:

<%= form_for :shop, :url => {:controller => 'shops', :action => 'aupdate', :id=> params[:id]}, :html=> {:id => "some-form-id", :multipart => true} do |f| %>

 .......

<% end %>

in your routes:

resources :shops do
   collection do
    ....
     post :aupdate
    ....
   end
end

in your controller:

def aupdate
   ....
   puts "ssssssssssssssssssssssssssss",params.inspect
   ....
end

Upvotes: 1

Related Questions