clem_c_rock
2011-May-05 05:21 UTC
Restful routing seems excessive at times - I want to simplify
I''m still trying to get used to REST concepts and forms
I have a very simple controller that updates user profile data. I have
this link that takes me to the controller:
<%= link_to(''Profile'', :controller =>
"operator_profile", :action => "edit")
%>
I then want to simply display the operator''s data like this:
def edit
@operator = Operator.find(current_operator.id)
end
and I want a form that posts to a update method in operator_profile. in
my routes I have
resources :operator_profile
I feel like I''m completely locked into the 7 base methods of REST and
everything else throws routing errors
I couldn''t even get the update method to work.
Can this be simplified?
--
View this message in context:
http://old.nabble.com/Restful-routing-seems-excessive-at-times---I-want-to-simplify-tp31547496p31547496.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Clem Rock
2011-May-05 05:23 UTC
Restful routing seems excessive at times - I want to simplify
I''m still trying to get used to REST concepts and forms
I have a very simple controller that updates user profile data. I
have this link that takes me to the controller:
<%= link_to(''Profile'', :controller =>
"operator_profile", :action =>
"edit") %>
I then want to simply display the operator''s data like this:
def edit
@operator = Operator.find(current_operator.id)
end
and I want a form that posts to a update method in operator_profile.
in my routes I have
resources :operator_profile
I feel like I''m completely locked into the 7 base methods of REST and
everything else throws routing errors
I couldn''t even get the update method to work.
Can this be simplified?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-May-05 06:18 UTC
Re: Restful routing seems excessive at times - I want to simplify
On May 5, 6:23 am, Clem Rock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m still trying to get used to REST concepts and forms > > I have a very simple controller that updates user profile data. I > have this link that takes me to the controller: > > <%= link_to(''Profile'', :controller => "operator_profile", :action => > "edit") %> > > I then want to simply display the operator''s data like this: > > def edit > @operator = Operator.find(current_operator.id) > end > > and I want a form that posts to a update method in operator_profile. > in my routes I have > > resources :operator_profile > > I feel like I''m completely locked into the 7 base methods of REST and > everything else throws routing errorsIt''s just shorthand - you could create the 7 routes on their own, ie match ''operator_profiles/:id'', :to => ''operator_profiles#index'' Or you can pass :only or :except to resources to say you don''t want all 7. Lastly since you have a concept of current_operator, maybe resources :operator_profiles just isn''t the right fit (since for excample your edit or update actions don''t require an id parameter). You could try the singleton one (ie resource :operator_profile) Fred> > I couldn''t even get the update method to work. > > Can this be simplified? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-May-05 08:17 UTC
Re: Restful routing seems excessive at times - I want to simplify
On 5 May 2011 06:21, clem_c_rock <clemrock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m still trying to get used to REST concepts and forms > > I have a very simple controller that updates user profile data. I have > this link that takes me to the controller: > > <%= link_to(''Profile'', :controller => "operator_profile", :action => "edit") > %> > > I then want to simply display the operator''s data like this: > > def edit > @operator = Operator.find(current_operator.id) > end > > and I want a form that posts to a update method in operator_profile. in > my routes I have > > resources :operator_profile > > I feel like I''m completely locked into the 7 base methods of REST and > everything else throws routing errors > > I couldn''t even get the update method to work. > > Can this be simplified?Your example shows you attempting to use edit and update, which are two of the standard routes, though in routes.rb you appear to be usin :operator_profile but that should be plural :operator_profiles. I am not sure exactly what you want to do, but if you just want to say that you do not need the other routes then use resources :operator_profiles, :only => [:edit, :update] To see which routes you have defined then use rake routes If you have not already done so then have a good look at the Rails Guide on routing. It will explain the above and much more. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
clem_c_rock
2011-May-05 11:11 UTC
Re: Restful routing seems excessive at times - I want to simplify
Thanks for your help. I realized before I saw your reply that I should have
made a operations_controller instead of the operator_profile_controller.
So I did that and I now have:
resources :operations in routes
and in operations controller I have all 7 rest methods.
And now I''m getting this:
No route matches {:controller=>"operators",
:action=>"edit"}
because of this link in application.html.erb:
<%= link_to(''Profile'', :controller =>
"operators", :action => "edit") %>
and when I do a rake routes - the only methods that are listed for operators
are:
operators GET /operators(.:format)
{:action=>"index", :controller=>"operators"}
POST /operators(.:format)
{:action=>"create", :controller=>"operators"}
My model is operator.rb
clem_c_rock wrote:>
>
> I''m still trying to get used to REST concepts and forms
>
> I have a very simple controller that updates user profile data. I have
> this link that takes me to the controller:
>
> <%= link_to(''Profile'', :controller =>
"operator_profile", :action =>
> "edit") %>
>
> I then want to simply display the operator''s data like this:
>
> def edit
> @operator = Operator.find(current_operator.id)
> end
>
> and I want a form that posts to a update method in operator_profile. in
> my routes I have
>
> resources :operator_profile
>
> I feel like I''m completely locked into the 7 base methods of REST
and
> everything else throws routing errors
>
> I couldn''t even get the update method to work.
>
> Can this be simplified?
>
>
--
View this message in context:
http://old.nabble.com/Restful-routing-seems-excessive-at-times---I-want-to-simplify-tp31547496p31549366.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-May-05 11:16 UTC
Re: Restful routing seems excessive at times - I want to simplify
On 5 May 2011 12:11, clem_c_rock <clemrock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Please don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate points in previous message.> > Thanks for your help. I realized before I saw your reply that I should have > made a operations_controller instead of the operator_profile_controller. > So I did that and I now have: > > resources :operations in routesDid you restart the server after changing routes.rb?> > and in operations controller I have all 7 rest methods. > > And now I''m getting this: > > No route matches {:controller=>"operators", :action=>"edit"} > > because of this link in application.html.erb: > > <%= link_to(''Profile'', :controller => "operators", :action => "edit") %>What have you got in routes.rb for operators? Colin> > and when I do a rake routes - the only methods that are listed for operators > are: > > operators GET /operators(.:format) > {:action=>"index", :controller=>"operators"} > POST /operators(.:format) > {:action=>"create", :controller=>"operators"}-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Clem Rock
2011-May-05 12:20 UTC
Re: Restful routing seems excessive at times - I want to simplify
Update:
I realized I should also attempt to go w/ a operations_controller
instead of the operator_profile_controller. So I did that and I now
have in routes:
resources :operations
and in operations controller I have all 7 rest methods.
And now I''m getting this:
No route matches {:controller=>"operators",
:action=>"edit"}
because of this link in application.html.erb:
<%= link_to(''Profile'', :controller =>
"operators", :action => "edit")
%>
and this fails as well:
<%= link_to(''Profile'', :controller =>
"operators_profile", :action =>
"edit") %>
My model is operator.rb
Here''s a dump of all my operator related routes:
[code]
operator_profile_index GET /operator_profile(.:format)
{:action=>"index", :controller=>"operator_profile"}
POST /operator_profile(.:format)
{:action=>"create", :controller=>"operator_profile"}
new_operator_profile GET /operator_profile/new(.:format)
{:action=>"new", :controller=>"operator_profile"}
edit_operator_profile GET /operator_profile/:id/edit(.:format)
{:action=>"edit", :controller=>"operator_profile"}
operator_profile GET /operator_profile/:id(.:format)
{:action=>"show", :controller=>"operator_profile"}
PUT /operator_profile/:id(.:format)
{:action=>"update", :controller=>"operator_profile"}
DELETE /operator_profile/:id(.:format)
{:action=>"destroy", :controller=>"operator_profile"}
operators GET /operators(.:format)
{:action=>"index", :controller=>"operators"}
POST /operators(.:format)
{:action=>"create", :controller=>"operators"}
new_operator GET /operators/new(.:format)
{:action=>"new", :controller=>"operators"}
edit_operator GET /operators/:id/edit(.:format)
{:action=>"edit", :controller=>"operators"}
operator GET /operators/:id(.:format)
{:action=>"show", :controller=>"operators"}
PUT /operators/:id(.:format)
{:action=>"update", :controller=>"operators"}
DELETE /operators/:id(.:format)
{:action=>"destroy", :controller=>"operators"}
[/code]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-May-05 12:34 UTC
Re: Re: Restful routing seems excessive at times - I want to simplify
On 5 May 2011 13:20, Clem Rock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Update: > > I realized I should also attempt to go w/ a operations_controller > instead of the operator_profile_controller. So I did that and I now > have in routes: > > resources :operations > > and in operations controller I have all 7 rest methods. > > And now I''m getting this: > > No route matches {:controller=>"operators", :action=>"edit"} > > because of this link in application.html.erb: > > <%= link_to(''Profile'', :controller => "operators", :action => "edit")Look at your routes and you will see that edit requires an id (so it knows which one to edit). You have not provided the id in the link.> %> > > and this fails as well: > > <%= link_to(''Profile'', :controller => "operators_profile", :action => > "edit") %>Same problem here I imagine. Colin> > My model is operator.rb > > Here''s a dump of all my operator related routes: > > [code] > operator_profile_index GET /operator_profile(.:format) > {:action=>"index", :controller=>"operator_profile"} > POST /operator_profile(.:format) > {:action=>"create", :controller=>"operator_profile"} > new_operator_profile GET /operator_profile/new(.:format) > {:action=>"new", :controller=>"operator_profile"} > edit_operator_profile GET /operator_profile/:id/edit(.:format) > {:action=>"edit", :controller=>"operator_profile"} > operator_profile GET /operator_profile/:id(.:format) > {:action=>"show", :controller=>"operator_profile"} > PUT /operator_profile/:id(.:format) > {:action=>"update", :controller=>"operator_profile"} > DELETE /operator_profile/:id(.:format) > {:action=>"destroy", :controller=>"operator_profile"} > > > operators GET /operators(.:format) > {:action=>"index", :controller=>"operators"} > POST /operators(.:format) > {:action=>"create", :controller=>"operators"} > new_operator GET /operators/new(.:format) > {:action=>"new", :controller=>"operators"} > edit_operator GET /operators/:id/edit(.:format) > {:action=>"edit", :controller=>"operators"} > operator GET /operators/:id(.:format) > {:action=>"show", :controller=>"operators"} > PUT /operators/:id(.:format) > {:action=>"update", :controller=>"operators"} > DELETE /operators/:id(.:format) > {:action=>"destroy", :controller=>"operators"} > [/code]-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-May-05 12:42 UTC
Re: Restful routing seems excessive at times - I want to simplify
On May 5, 1:20 pm, Clem Rock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Update: > > I realized I should also attempt to go w/ a operations_controller > instead of the operator_profile_controller. So I did that and I now > have in routes: > > resources :operations > > and in operations controller I have all 7 rest methods. > > And now I''m getting this: > > No route matches {:controller=>"operators", :action=>"edit"} > > because of this link in application.html.erb: > > <%= link_to(''Profile'', :controller => "operators", :action => "edit") > %> > > and this fails as well: > > <%= link_to(''Profile'', :controller => "operators_profile", :action => > "edit") %> > > My model is operator.rb >Your issue is that the restful edit/update routes requires an id (which object to edit/update) and you''re not providing one, which is why I suggested you look at singleton resources. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Ruther Nill
2011-May-06 02:42 UTC
Re: Restful routing seems excessive at times - I want to simplify
On Thu, May 5, 2011 at 7:11 PM, clem_c_rock <clemrock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for your help. I realized before I saw your reply that I should > have > made a operations_controller instead of the operator_profile_controller. > So I did that and I now have: > > resources :operations in routes > > and in operations controller I have all 7 rest methods. > > And now I''m getting this: > > No route matches {:controller=>"operators", :action=>"edit"} > > because of this link in application.html.erb: > > <%= link_to(''Profile'', :controller => "operators", :action => "edit") %> > > and when I do a rake routes - the only methods that are listed for > operators > are: > > operators GET /operators(.:format) > {:action=>"index", :controller=>"operators"} > POST /operators(.:format) > {:action=>"create", :controller=>"operators"} > >i bet you have something like resources :operators, :only => [:index, :create] in your routes file. Since you''re trying to go the the edit action of your operators controller, you need to add the edit action to your routes. My model is operator.rb> > > > > clem_c_rock wrote: > > > > > > I''m still trying to get used to REST concepts and forms > > > > I have a very simple controller that updates user profile data. I have > > this link that takes me to the controller: > > > > <%= link_to(''Profile'', :controller => "operator_profile", :action => > > "edit") %> > > > > I then want to simply display the operator''s data like this: > > > > def edit > > @operator = Operator.find(current_operator.id) > > end > > > > and I want a form that posts to a update method in operator_profile. > in > > my routes I have > > > > resources :operator_profile > > > > I feel like I''m completely locked into the 7 base methods of REST and > > everything else throws routing errors > > > > I couldn''t even get the update method to work. > > > > Can this be simplified? > > > > > > -- > View this message in context: > http://old.nabble.com/Restful-routing-seems-excessive-at-times---I-want-to-simplify-tp31547496p31549366.html > Sent from the RubyOnRails Users mailing list archive at Nabble.com. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
paul h
2011-May-06 12:27 UTC
Re: Restful routing seems excessive at times - I want to simplify
Just a couple of points to add - might be typos in the post, or may be relevant to your controllers.... On May 5, 1:20 pm, Clem Rock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Update: > > I realized I should also attempt to go w/ a operations_controller > instead of the operator_profile_controller. So I did that and I now > have in routes: > > resources :operations** operations **> > and in operations controller I have all 7 rest methods. > > And now I''m getting this: > > No route matches {:controller=>"operators", :action=>"edit"}** operators **> > because of this link in application.html.erb: > > <%= link_to(''Profile'', :controller => "operators", :action => "edit") > %>** operators **> > and this fails as well: > > <%= link_to(''Profile'', :controller => "operators_profile", :action => > "edit") %> > > My model is operator.rb > > Here''s a dump of all my operator related routes:Is your controller operator[s], or operations?> > [code] > operator_profile_index GET /operator_profile(.:format) > {:action=>"index", :controller=>"operator_profile"} > POST /operator_profile(.:format) > {:action=>"create", :controller=>"operator_profile"} > new_operator_profile GET /operator_profile/new(.:format) > {:action=>"new", :controller=>"operator_profile"} > edit_operator_profile GET /operator_profile/:id/edit(.:format) > {:action=>"edit", :controller=>"operator_profile"} > operator_profile GET /operator_profile/:id(.:format) > {:action=>"show", :controller=>"operator_profile"} > PUT /operator_profile/:id(.:format) > {:action=>"update", :controller=>"operator_profile"} > DELETE /operator_profile/:id(.:format) > {:action=>"destroy", :controller=>"operator_profile"} > > operators GET /operators(.:format) > {:action=>"index", :controller=>"operators"} > POST /operators(.:format) > {:action=>"create", :controller=>"operators"} > new_operator GET /operators/new(.:format) > {:action=>"new", :controller=>"operators"} > edit_operator GET /operators/:id/edit(.:format) > {:action=>"edit", :controller=>"operators"} > operator GET /operators/:id(.:format) > {:action=>"show", :controller=>"operators"} > PUT /operators/:id(.:format) > {:action=>"update", :controller=>"operators"} > DELETE /operators/:id(.:format) > {:action=>"destroy", :controller=>"operators"} > [/code] > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Eugen Ciur
2011-May-06 13:00 UTC
Re: Restful routing seems excessive at times - I want to simplify
For this route
edit_operator_profile GET /operator_profile/:id/edit(.:format)
{:action=>"edit",
:controller=>"operator_profile"}
Below is wrong
<%=link_to(''Profile'',:controller =>
"operators_profile",:action
=>"edit")%>
Correct will be
<%=link_to(''Profile'',:controller =>
"operators_profile",:action
=>"edit", :id => @your_operator_profile)%>
Or even shorter
<%=link_to(''Profile'',edit_operator_profile(@your_operator_profile))%>
Restful resources are really easy if you look carefully at output of
rake routes
----
http://blog.eugen.co
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.