For some reason the following form always sends me to the index action
<% form_for :league, :url => admin_leagues_url do |f| %>
...
<% end %>
If I set the :url to leagues_url (to which is also set in the routes
file) I am routed properly to the create action.
Here is the rendered form:
<form action="http://localhost:3000/admin/leagues"
method="post">
...
</form>
Here is part of my routing file:
map.namespace :admin do |admin|
admin.resources :leagues
end
Is this a bug or am I missing something?
Thanks for the help.
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
You can try out `rake routes` to see how your routes.rb is working. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Everything seems to be as expected (not sure how readable this will be):
======== admin_leagues GET /admin/leagues
{:controller=>"admin/leagues", :action=>"index"}
formatted_admin_leagues GET /admin/leagues.:format
{:controller=>"admin/leagues", :action=>"index"}
POST /admin/leagues
{:controller=>"admin/leagues", :action=>"create"}
POST /admin/leagues.:format
{:controller=>"admin/leagues", :action=>"create"}
new_admin_league GET /admin/leagues/new
{:controller=>"admin/leagues", :action=>"new"}
formatted_new_admin_league GET /admin/leagues/new.:format
{:controller=>"admin/leagues", :action=>"new"}
edit_admin_league GET /admin/leagues/:id/edit
{:controller=>"admin/leagues", :action=>"edit"}
formatted_edit_admin_league GET /admin/leagues/:id/edit.:format
{:controller=>"admin/leagues", :action=>"edit"}
admin_league GET /admin/leagues/:id
{:controller=>"admin/leagues", :action=>"show"}
formatted_admin_league GET /admin/leagues/:id.:format
{:controller=>"admin/leagues", :action=>"show"}
PUT /admin/leagues/:id
{:controller=>"admin/leagues", :action=>"update"}
PUT /admin/leagues/:id.:format
{:controller=>"admin/leagues", :action=>"update"}
DELETE /admin/leagues/:id
{:controller=>"admin/leagues", :action=>"destroy"}
DELETE /admin/leagues/:id.:format
{:controller=>"admin/leagues", :action=>"destroy"}
POST /session
{:controller=>"sessions", :action=>"create"}
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
That''s not readable.... Do you find your `admin_leagues` is listed under POST and create method? I can''t find them. Are you sure you have "admin/leagues" controller? in /app/controllers/admin/leagues_controller.rb ? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Jun 15, 2008 at 12:00 AM, Chris Olsen < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > For some reason the following form always sends me to the index action > > <% form_for :league, :url => admin_leagues_url do |f| %> > ... > <% end %> > >I believe that the preferred way to do this is form_for([:admin, @league]) do |f| Assuming your controller sets @league to either a new (in the new action) or existing (in the edit action) instance of League. This should automatically generate the right url in the admin namespace to either post or put the form depending on wheter or not @league.new_record? is true. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick Denatale wrote:> I believe that the preferred way to do this is > > form_for([:admin, @league]) do |f| > > Assuming your controller sets @league to either a new (in the new > action) or > existing (in the edit action) instance of League. This should > automatically > generate the right url in the admin namespace to either post or put the > form > depending on wheter or not @league.new_record? is true.That way worked. The weird thing is that I re-tried the way I did it the first time and this time it worked. Not sure why since I had restarted the server a number of time when trying to figure it out last night. I was unaware that you could pass in an array to the form for to allow the admin subdir to be added to the url, which is why I didn''t use that method in the first place. Thanks for the help. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The only difference between the index action and the create action is whether you''re doing a get (index) or post (create). You can always make sure you are using the right method by adding a :method=>xxx to the form_for. On Jun 15, 11:19 am, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Rick Denatale wrote: > > I believe that the preferred way to do this is > > > form_for([:admin, @league]) do |f| > > > Assuming your controller sets @league to either a new (in the new > > action) or > > existing (in the edit action) instance of League. This should > > automatically > > generate the right url in the admin namespace to either post or put the > > form > > depending on wheter or not @league.new_record? is true. > > That way worked. The weird thing is that I re-tried the way I did it > the first time and this time it worked. Not sure why since I had > restarted the server a number of time when trying to figure it out last > night. > > I was unaware that you could pass in an array to the form for to allow > the admin subdir to be added to the url, which is why I didn''t use that > method in the first place. > > Thanks for the help. > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Jun 15, 2008 at 11:19 AM, Chris Olsen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Rick Denatale wrote: >> I believe that the preferred way to do this is >> >> form_for([:admin, @league]) do |f| >> >> Assuming your controller sets @league to either a new (in the new >> action) or existing (in the edit action) instance of League. This >> should automatically generate the right url in the admin >> namespace to either post or put the form depending on >> wheter or not @league.new_record? is true. > > That way worked. The weird thing is that I re-tried the way I did it > the first time and this time it worked. Not sure why since I had > restarted the server a number of time when trying to figure it out last > night.Could it be that your original example read: <% form_for :league, :url => admin_leagues_url do |f| %> instead of <% form_for :league, :url => admin_league_url do |f| %> (Notice the difference between "admin_leagues_url" (plural) and "admin_league_url" (singular)). --wpd --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> The only difference between the index action and the create action is > whether you''re doing a get (index) or post (create). You can always > make sure you are using the right method by adding a :method=>xxx to > the form_for.Ya, I tried that, but the initial form was rendering with the method = "post" already.> Could it be that your original example read: > > <% form_for :league, :url => admin_leagues_url do |f| %> > > instead of > > <% form_for :league, :url => admin_league_url do |f| %> > > (Notice the difference between "admin_leagues_url" (plural) and > "admin_league_url" (singular)). > > --wpdIt is the plural version that I want for a POST. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---