Adding a Route to a Rails 3 Controller

I am still getting Rails freeze and I ran into a problem which, in my opinion, should be pretty simple. Hoping someone could show me the error of my ways.

I read this post: How to add a RESTful custom route to a Rails application? which has a ton of good information (for Rails 2, I'm using Rails 3), but I can't get my code to work. Here where I am:

I added my .rb routes as follows:

  resources :proposals do
    member do
      put :change_status
    end
  end

I added mycontroller.rb suggestions as follows:

  def change_status
    @proposal = Proposal.find(params[:id])

    respond_to do |format|
      if @proposal.change_status
        format.html { redirect_to(@proposal, :notice => 'Proposal status was changed.'') }
        format.xml  { head :ok }
      else
        format.html { redirect_to(@proposal, :error => 'Proposal failed to transition.') }
        format.xml  { render :xml => @proposal.errors, :status => :unprocessable_entity }
      end
    end
  end

And finally, in my opinion, I refer to it as follows:

<%= link_to "Deliver to Client", change_status_proposal_path(@proposal) %>

But when I access my site by going to

http://localhost:3000/proposals/4/change_status

I get the following error:

Routing error

No matching routes "/ offer / 4 / change_status"

, - , , . , - - , .

!

+3
1

, put . , :

<%= link_to "Deliver to Client", change_status_proposal_path(@proposal), :method=>:put %>

, URL- , POSTED. URL- GET.

+2

Source: https://habr.com/ru/post/1795756/


All Articles