开发者

why is my remote_form_tag with :action defined not posting the action?

开发者 https://www.devze.com 2023-01-22 03:50 出处:网络
This is what I\'ve used with remote_form_tag: <% form_remote_tag(:url => {:controller => \'/companies\', :action => \'update\'},

This is what I've used with remote_form_tag:

<% form_remote_tag(:url => {:controller => '/companies', :action => 'update'},
      :update => 'tags') do  %>
      <%= text_field :company, :tag_list %> 
       <%= submit_tag 'Save' %> 
  <% end %>

This is in a Company.view, where Company is a model that is acts_as_taggable_on enabled.

My expectation is that, via ajax, a post is made to companies/10/update

But, instead, what is posted is:

http://localhost:3000/companies/10

and the response is:

No action responded to 10. Actions: create, destroy, edit, email_this_week, index, new, show, and update

This is the update method in CompaniesController:

 def update
    @company = Company.find(params[:id])
    if request.xhr?
      # add the given tag 开发者_运维问答to the company
      @company.tags << params[:company][:taglist]
      @company.save
      render :partial => 'tags'
    else
      if @company.update_attributes(params[:company])
        flash[:notice] = "Successfully updated company."
        redirect_to @company
      else
        render :action => 'edit'
      end
    end
  end

Help...?

     DELETE /companies/:company_id/contacts/:id(.:forma
   {:controller=>"contacts", :action=>"destroy"}
            companies GET    /companies(.:format)
   {:controller=>"companies", :action=>"index"}
                      POST   /companies(.:format)
   {:controller=>"companies", :action=>"create"}
          new_company GET    /companies/new(.:format)
   {:controller=>"companies", :action=>"new"}
         edit_company GET    /companies/:id/edit(.:format)
   {:controller=>"companies", :action=>"edit"}
              company GET    /companies/:id(.:format)
   {:controller=>"companies", :action=>"show"}
                      PUT    /companies/:id(.:format)
   {:controller=>"companies", :action=>"update"}
                      DELETE /companies/:id(.:format)
   {:controller=>"companies", :action=>"destroy"}


When you update a resource like Company with ID 10, Rails will use the RESTful route:

PUT /companies/10

The PUT method is taken into account when routing your request. Taken from your routes:

PUT    /companies/:id(.:format)
  {:controller=>"companies", :action=>"update"}

This is correct behaviour for Rails. Just implement the update method in your CompaniesController.

If you require more info on RESTful routes in Rails, check up on this document: http://guides.rubyonrails.org/routing.html

0

精彩评论

暂无评论...
验证码 换一张
取 消