form_for not passing id?

51 views
Skip to first unread message

Dave Castellano

unread,
Nov 2, 2014, 8:57:43 PM11/2/14
to rubyonra...@googlegroups.com
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

--
Posted via http://www.ruby-forum.com/.

BalaRaju Vankala

unread,
Nov 2, 2014, 11:46:27 PM11/2/14
to rubyonra...@googlegroups.com
Hey Dave, 

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



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
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.



--
----------------------------------------------------------------------------------------------------
Thank You.

Best Wishes,
 
BalaRaju Vankala,
8886565300.


Sampath Munasinghe

unread,
Nov 3, 2014, 2:41:25 AM11/3/14
to rubyonra...@googlegroups.com
Form_for will get the :id by default. which version are you using and please paste the controller code here. tks

Dave Castellano

unread,
Nov 3, 2014, 7:18:40 AM11/3/14
to rubyonra...@googlegroups.com
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
> <foreve...@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

Matt Jones

unread,
Nov 3, 2014, 8:05:32 AM11/3/14
to rubyonra...@googlegroups.com


On Sunday, 2 November 2014 20:57:43 UTC-5, Ruby-Forum.com User wrote:
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


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

Dave Castellano

unread,
Nov 3, 2014, 8:50:37 AM11/3/14
to rubyonra...@googlegroups.com
Matt Jones wrote in post #1161637:
Thank you, specifying the URL did it nicely!

Dave

BalaRaju Vankala

unread,
Nov 4, 2014, 8:00:17 AM11/4/14
to rubyonra...@googlegroups.com
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. 


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages