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

Source:

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

Thanks
Dave C., MD

Hey Dave,

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

On Mon, Nov 3, 2014 at 7:27 AM, Dave C. [email protected]
wrote:

    <%= f.submit 'Update', :class => 'btn btn-primary' %>

Thanks
To post to this group, send email to [email protected].
To view this discussion on the web visit

https://groups.google.com/d/msgid/rubyonrails-talk/04269e5bd1fe0e2fa4f71eabc7f91e1f%40ruby-forum.com

.
For more options, visit https://groups.google.com/d/optout.

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 V.
[email protected]

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 V.
[email protected]

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

On Sunday, 2 November 2014 20:57:43 UTC-5, Ruby-Forum.com User wrote:

  ...
    <%= 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

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 J.

Matt J. wrote in post #1161637:

On Sunday, 2 November 2014 20:57:43 UTC-5, Ruby-Forum.com User wrote:

  ...
    <%= 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

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 J.

Thank you, specifying the URL did it nicely!

Dave

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.

On Mon, Nov 3, 2014 at 7:19 PM, Dave C. [email protected]
wrote:

Thank you, specifying the URL did it nicely!
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit

https://groups.google.com/d/msgid/rubyonrails-talk/5c4d48bf605038b7c434b6869f19f4a9%40ruby-forum.com

.
For more options, visit https://groups.google.com/d/optout.