form_for not passing id?

Hi, When I try to update a field using the update button I am getting the error: No route matches [PATCH] "/profile". Its obviously missing the /:id but I can't figure out why...

I am using a form_for in an edit view.

<%= form_for @profile, :html => { :class => 'form-horizontal '} do |f| %>       ...         <%= f.submit 'Update', :class => 'btn btn-primary' %>       ... <% end %>

@profile contains #<Profile:0x00000104c26398> as it should.

routes contains: resources :profiles and the resulting routes appear OK

Do I have to somehow configure the form_for to pass the :id to the route?

Thanks Dave Castellano, MD

Hey Dave,

I think may be error in your controller, can you once again check profiles controller edit action

Form_for will get the :id by default. which version are you using and please paste the controller code here. tks

sampath n. wrote in post #1161624:

Form_for will get the :id by default. which version are you using and please paste the controller code here. tks

On Mon, Nov 3, 2014 at 10:16 AM, BalaRaju Vankala <foreverbala4u@gmail.com>

Rails 4.0.3

Controller code: def edit     @banner_title = "Edit Profile"     @profile = Profile.find(current_user.id)   end

  def update     @profile = Profile.find(current_user.id)     respond_to do |format|       if @profile.update_attributes(params[:profile])         format.html { redirect_to user_url, notice: 'Profile was successfully updated.' }         format.json { head :ok }       else         @title = "Edit profile"         format.html { render action: "edit" }         format.json { render json: @subject.errors, status: :unprocessable_entity }       end     end   end

From the route it’s generating, I suspect you have a resource :profile someplace above this. That matches the controller actions you’re showing, which use current_user.id instead of params[:id]. You’ll likely need to specify the URL explicitly to form_for.

–Matt Jones

Matt Jones wrote in post #1161637:

Hey Dave,

Before any controller action use "raise params.inspect ", you will get parameters coming from Form. You have to use that parameters only .

In your case just add this line in edit action (Edit Method) “raise params.inspect”. you will get all parameters.