Hey all,
Rails guide doesnt cover with_options in Rails 3:
http://guides.rubyonrails.org/routing.html
The book The Rails 3 Way makes no reference to with_options except for
one page briefly.
And I cannot find a decent tutorial to cover what I am trying to do.
I have this:
map.with_options :name_prefix => "dashboard_", :path_prefix =>
"dashboard", :controller => "dashboard" do |dashboard|
dashboard.sidebar ".:format"
dashboard.charts ".:format"
dashboard.action_items ".:format"
dashboard.performance ".:format"
dashboard.site_menu ".:format"
dashboard.quick_links ".:format"
dashboard.perf_randomizations ".:format"
end
Basically all of these methods "sidebar", "charts", etc are
all methods
of the dashboard controller. I want them all to have a path helper of
dashboard_#{action}_url, where action is the action (e.g.
dashboard_sidebar_url). I want them all to be able to respond to both
html format and json. However, I dont know how to do this in Rails 3.
The above code raises exception:
config/routes.rb:7:in `block in <top (required)>'': undefined
local
variable or method `map'' for
#<ActionDispatch::Routing::Mapper:0x00000102ca3570> (NameError)
Some stackoverflow posts show similar situations but not specifically
what I am trying to do here.
thanks for response
--
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.
I tried this:
scope :path => ''/dashboard'', :name_prefix =>
"dashboard_", :path_prefix
=> "dashboard", :controller => :dashboard do
match ''/sidebar.:format'' => :sidebar
match ''/charts.:format'' => :charts
match ''/action_items.:format'' => :action_items
match ''/performance.:format'' => :performance
end
not sure yet if it is going to give me dashboard_sidebar_url, for
example, as a route helper.
--
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.
I tried a named route and I get this: undefined local variable or method `dashboard_sidebar_path'' any idea? -- 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.
John Merlino wrote in post #1019442:> Hey all, > > Rails guide doesnt cover with_options in Rails 3: > > http://guides.rubyonrails.org/routing.html > > The book The Rails 3 Way makes no reference to with_options except for > one page briefly. >The docs say with_options is still part of rails 3.0.9: http://apidock.com/rails/Object/with_options ...but like a lot of rails stuff that method probably just serves to obfuscate your code--even though it''s terser.> And I cannot find a decent tutorial to cover what I am trying to do. > > I have this: > > map.with_optionsWhoa. In rails 3, you write routes in a block that looks like this: TestApp::Application.routes.draw do ... end not like rails 2: ActionController::Routing::Routes.draw do |map| map.do_something end If you write this: TestApp::Application.routes.draw do map.foo.bar end ...then ruby doesn''t know what map is.> :name_prefix => "dashboard_", :path_prefix => >"dashboard", :controller => "dashboard" do |dashboard| > dashboard.sidebar ".:format" > dashboard.charts ".:format" > dashboard.action_items ".:format" > dashboard.performance ".:format" > dashboard.site_menu ".:format" > dashboard.quick_links ".:format" > dashboard.perf_randomizations ".:format" > end > > Basically all of these methods "sidebar", "charts", etc are all methods > of the dashboard controller. I want them all to have a path helper of > dashboard_#{action}_url, where action is the action (e.g. > dashboard_sidebar_url). I want them all to be able to respond to both > html format and json. However, I dont know how to do this in Rails 3. >See if this works: match ''some/url'' => "dashboard#sidebar", :as => "dashboard_sidebar" match ''another/url'' => "dashboard#charts", :as => "dashboard_charts" -- 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.
I havent tested it yet but thanks for response -- 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.
So I tried using the :as option for the named route so I could have
dashboard_sidebar_path helpers.
scope :path => ''/dashboard'', :controller => :dashboard
do
match ''/sidebar.:format'' => :sidebar, :as =>
''dashboard_sidebar''
match ''/charts.:format'' => :charts
match ''/action_items.:format'' => :action_items
match ''/performance.:format'' => :performance
end
However, strangely enough, it reports this error when using the
dashboard_sidebar_path helper:
No route matches {:controller=>"dashboard",
:action=>"sidebar"}
As you can see the controller is defined with :controller in the
scope, so I dont know why the error.
thanks for response
On Aug 31, 5:42 pm, John Merlino
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> I havent tested it yet but thanks for response
>
> --
> 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.
Yeah, in old Rails (2.x) the block created a map variable (you could observe "do |map|" in the first line) but in Rails 3 the API has changed and this variable is not created anymore, hence you can´t use it. Rodrigo Vieira Programmer +55 (81) 98935478 http://www.rodrigoalvesvieira.com https://github.com/rodrigoalvesvieira http://twitter.com/#!/rodrigoalvieira On Sun, Sep 4, 2011 at 3:42 PM, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> So I tried using the :as option for the named route so I could have > dashboard_sidebar_path helpers. > > scope :path => ''/dashboard'', :controller => :dashboard do > match ''/sidebar.:format'' => :sidebar, :as => ''dashboard_sidebar'' > match ''/charts.:format'' => :charts > match ''/action_items.:format'' => :action_items > match ''/performance.:format'' => :performance > end > > However, strangely enough, it reports this error when using the > dashboard_sidebar_path helper: > > No route matches {:controller=>"dashboard", :action=>"sidebar"} > > > As you can see the controller is defined with :controller in the > scope, so I dont know why the error. > > thanks for response > > On Aug 31, 5:42 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > I havent tested it yet but thanks for response > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
thanks for response
I see some other strange stuff going on.
for example, I have something like this:
resources :players do
member do
get :reject
end
resources :saleries
end
And I use a link_to helper to try to access the reject_player_path in
my dashboard show haml file and I get an error:
No route matches {:action=>"reject",
:controller=>"players"}
And I try to even just try a player_path helper, which should exist
for show (when using link_to in other words get requests) and update
(when using form_for in other words post requests), yet I get this
error:
No route matches {:action=>"show",
:controller=>"players"}
But obviously, these exceptions are wrong, as when I run rake routes,
these matches indeed do exist:
root /
(.:format)
{:controller=>"dashboard", :action=>"show"}
team_players GET /teams/:team_id/
players(.:format)
{:action=>"index", :controller=>"players"}
POST /teams/:team_id/
players(.:format)
{:action=>"create", :controller=>"players"}
new_team_player GET /teams/:team_id/players/
new(.:format) {:action=>"new",
:controller=>"players"}
edit_team_player GET /teams/:team_id/players/:id/
edit(.:format) {:action=>"edit",
:controller=>"players"}
team_player GET /teams/:team_id/
players/:id(.:format)
{:action=>"show", :controller=>"players"}
PUT /teams/:team_id/
players/:id(.:format)
{:action=>"update", :controller=>"players"}
DELETE /teams/:team_id/
players/:id(.:format)
{:action=>"destroy", :controller=>"players"}
teams GET /
teams(.:format)
{:action=>"index", :controller=>"teams"}
POST /
teams(.:format)
{:action=>"create", :controller=>"teams"}
new_team GET /teams/
new(.:format)
{:action=>"new", :controller=>"teams"}
edit_team GET /teams/:id/
edit(.:format)
{:action=>"edit", :controller=>"teams"}
team GET /
teams/:id(.:format)
{:action=>"show", :controller=>"teams"}
PUT /
teams/:id(.:format)
{:action=>"update", :controller=>"teams"}
DELETE /
teams/:id(.:format)
{:action=>"destroy", :controller=>"teams"}
reject_player GET /players/:id/
reject(.:format)
{:action=>"reject", :controller=>"players"}
player_saleries GET /players/:player_id/
saleries(.:format)
{:action=>"index", :controller=>"saleries"}
POST /players/:player_id/
saleries(.:format)
{:action=>"create", :controller=>"saleries"}
new_player_salery GET /players/:player_id/saleries/
new(.:format) {:action=>"new",
:controller=>"saleries"}
edit_player_salery GET /players/:player_id/saleries/:id/
edit(.:format) {:action=>"edit",
:controller=>"saleries"}
player_salery GET /players/:player_id/
saleries/:id(.:format) {:action=>"show",
:controller=>"saleries"}
PUT /players/:player_id/
saleries/:id(.:format)
{:action=>"update", :controller=>"saleries"}
DELETE /players/:player_id/
saleries/:id(.:format)
{:action=>"destroy", :controller=>"saleries"}
players GET /
players(.:format)
{:action=>"index", :controller=>"players"}
POST /
players(.:format)
{:action=>"create", :controller=>"players"}
new_player GET /players/
new(.:format)
{:action=>"new", :controller=>"players"}
edit_player GET /players/:id/
edit(.:format)
{:action=>"edit", :controller=>"players"}
player GET /
players/:id(.:format)
{:action=>"show", :controller=>"players"}
PUT /
players/:id(.:format)
{:action=>"update", :controller=>"players"}
DELETE /
players/:id(.:format)
{:action=>"destroy", :controller=>"players"}
saleries GET /
saleries(.:format)
{:action=>"index", :controller=>"saleries"}
POST /
saleries(.:format)
{:action=>"create", :controller=>"saleries"}
new_salery GET /saleries/
new(.:format)
{:action=>"new", :controller=>"saleries"}
edit_salery GET /saleries/:id/
edit(.:format)
{:action=>"edit", :controller=>"saleries"}
salery GET /
saleries/:id(.:format)
{:action=>"show", :controller=>"saleries"}
PUT /
saleries/:id(.:format)
{:action=>"update", :controller=>"saleries"}
DELETE /
saleries/:id(.:format)
{:action=>"destroy", :controller=>"saleries"}
dashboard_sidebar /dashboard/
sidebar.:format
{:controller=>"dashboard", :action=>"sidebar"}
/dashboard/
charts.:format
{:controller=>"dashboard", :action=>"charts"}
/dashboard/
action_items.:format
{:controller=>"dashboard", :action=>"action_items"}
/dashboard/
performance.:format
{:controller=>"dashboard", :action=>"performance"}
So it seems to be contradicting.
On Sep 4, 3:50 pm, Rodrigo Alves Vieira
<rodrig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Yeah, in old Rails (2.x) the block created a map variable (you could
observe
> "do |map|" in the first line) but in Rails 3 the API has changed
and this
> variable is not created anymore, hence you can´t use it.
>
> Rodrigo Vieira
> Programmer
>
> +55 (81)
98935478http://www.rodrigoalvesvieira.comhttps://github.com/rodrigoalvesvieirahttp://twitter.com/#!/rodrigoalvieira
>
>
>
>
>
>
>
> On Sun, Sep 4, 2011 at 3:42 PM, John Merlino
<stoici...-YDxpq3io04c@public.gmane.org> wrote:
> > So I tried using the :as option for the named route so I could have
> > dashboard_sidebar_path helpers.
>
> > scope :path => ''/dashboard'', :controller =>
:dashboard do
> > match ''/sidebar.:format'' => :sidebar, :as
=> ''dashboard_sidebar''
> > match ''/charts.:format'' => :charts
> > match ''/action_items.:format'' =>
:action_items
> > match ''/performance.:format'' => :performance
> > end
>
> > However, strangely enough, it reports this error when using the
> > dashboard_sidebar_path helper:
>
> > No route matches {:controller=>"dashboard",
:action=>"sidebar"}
>
> > As you can see the controller is defined with :controller in the
> > scope, so I dont know why the error.
>
> > thanks for response
>
> > On Aug 31, 5:42 pm, John Merlino
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
> > > I havent tested it yet but thanks for response
>
> > > --
> > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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.
bump The reason why player path wasnt working was because it required an instance of player: player_path(@player). But I am still stuck as to why dashboard_sidebar_path isn''t working when the route clearly shows up when running rake routes. On Sep 4, 4:20 pm, John Merlino <stoici...-YDxpq3io04c@public.gmane.org> wrote:> thanks for response > > I see some other strange stuff going on. > > for example, I have something like this: > > resources :players do > member do > get :reject > end > resources :saleries > end > > And I use a link_to helper to try to access the reject_player_path in > my dashboard show haml file and I get an error: > > No route matches {:action=>"reject", :controller=>"players"} > > And I try to even just try a player_path helper, which should exist > for show (when using link_to in other words get requests) and update > (when using form_for in other words post requests), yet I get this > error: > > No route matches {:action=>"show", :controller=>"players"} > > But obviously, these exceptions are wrong, as when I run rake routes, > these matches indeed do exist: > > root / > (.:format) > {:controller=>"dashboard", :action=>"show"} > team_players GET /teams/:team_id/ > players(.:format) > {:action=>"index", :controller=>"players"} > POST /teams/:team_id/ > players(.:format) > {:action=>"create", :controller=>"players"} > new_team_player GET /teams/:team_id/players/ > new(.:format) {:action=>"new", :controller=>"players"} > edit_team_player GET /teams/:team_id/players/:id/ > edit(.:format) {:action=>"edit", :controller=>"players"} > team_player GET /teams/:team_id/ > players/:id(.:format) > {:action=>"show", :controller=>"players"} > PUT /teams/:team_id/ > players/:id(.:format) > {:action=>"update", :controller=>"players"} > DELETE /teams/:team_id/ > players/:id(.:format) > {:action=>"destroy", :controller=>"players"} > teams GET / > teams(.:format) > {:action=>"index", :controller=>"teams"} > POST / > teams(.:format) > {:action=>"create", :controller=>"teams"} > new_team GET /teams/ > new(.:format) > {:action=>"new", :controller=>"teams"} > edit_team GET /teams/:id/ > edit(.:format) > {:action=>"edit", :controller=>"teams"} > team GET / > teams/:id(.:format) > {:action=>"show", :controller=>"teams"} > PUT / > teams/:id(.:format) > {:action=>"update", :controller=>"teams"} > DELETE / > teams/:id(.:format) > {:action=>"destroy", :controller=>"teams"} > reject_player GET /players/:id/ > reject(.:format) > {:action=>"reject", :controller=>"players"} > player_saleries GET /players/:player_id/ > saleries(.:format) > {:action=>"index", :controller=>"saleries"} > POST /players/:player_id/ > saleries(.:format) > {:action=>"create", :controller=>"saleries"} > new_player_salery GET /players/:player_id/saleries/ > new(.:format) {:action=>"new", :controller=>"saleries"} > edit_player_salery GET /players/:player_id/saleries/:id/ > edit(.:format) {:action=>"edit", :controller=>"saleries"} > player_salery GET /players/:player_id/ > saleries/:id(.:format) {:action=>"show", :controller=>"saleries"} > PUT /players/:player_id/ > saleries/:id(.:format) > {:action=>"update", :controller=>"saleries"} > DELETE /players/:player_id/ > saleries/:id(.:format) > {:action=>"destroy", :controller=>"saleries"} > players GET / > players(.:format) > {:action=>"index", :controller=>"players"} > POST / > players(.:format) > {:action=>"create", :controller=>"players"} > new_player GET /players/ > new(.:format) > {:action=>"new", :controller=>"players"} > edit_player GET /players/:id/ > edit(.:format) > {:action=>"edit", :controller=>"players"} > player GET / > players/:id(.:format) > {:action=>"show", :controller=>"players"} > PUT / > players/:id(.:format) > {:action=>"update", :controller=>"players"} > DELETE / > players/:id(.:format) > {:action=>"destroy", :controller=>"players"} > saleries GET / > saleries(.:format) > {:action=>"index", :controller=>"saleries"} > POST / > saleries(.:format) > {:action=>"create", :controller=>"saleries"} > new_salery GET /saleries/ > new(.:format) > {:action=>"new", :controller=>"saleries"} > edit_salery GET /saleries/:id/ > edit(.:format) > {:action=>"edit", :controller=>"saleries"} > salery GET / > saleries/:id(.:format) > {:action=>"show", :controller=>"saleries"} > PUT / > saleries/:id(.:format) > {:action=>"update", :controller=>"saleries"} > DELETE / > saleries/:id(.:format) > {:action=>"destroy", :controller=>"saleries"} > dashboard_sidebar /dashboard/ > sidebar.:format > {:controller=>"dashboard", :action=>"sidebar"} > /dashboard/ > charts.:format > {:controller=>"dashboard", :action=>"charts"} > /dashboard/ > action_items.:format > {:controller=>"dashboard", :action=>"action_items"} > /dashboard/ > performance.:format > {:controller=>"dashboard", :action=>"performance"} > > So it seems to be contradicting. > > On Sep 4, 3:50 pm, Rodrigo Alves Vieira <rodrig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Yeah, in old Rails (2.x) the block created a map variable (you could observe > > "do |map|" in the first line) but in Rails 3 the API has changed and this > > variable is not created anymore, hence you can´t use it. > > > Rodrigo Vieira > > Programmer > > > +55 (81) 98935478http://www.rodrigoalvesvieira.comhttps://github.com/rodrigoalvesvieir... > > > On Sun, Sep 4, 2011 at 3:42 PM, John Merlino <stoici...-YDxpq3io04c@public.gmane.org> wrote: > > > So I tried using the :as option for the named route so I could have > > > dashboard_sidebar_path helpers. > > > > scope :path => ''/dashboard'', :controller => :dashboard do > > > match ''/sidebar.:format'' => :sidebar, :as => ''dashboard_sidebar'' > > > match ''/charts.:format'' => :charts > > > match ''/action_items.:format'' => :action_items > > > match ''/performance.:format'' => :performance > > > end > > > > However, strangely enough, it reports this error when using the > > > dashboard_sidebar_path helper: > > > > No route matches {:controller=>"dashboard", :action=>"sidebar"} > > > > As you can see the controller is defined with :controller in the > > > scope, so I dont know why the error. > > > > thanks for response > > > > On Aug 31, 5:42 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > I havent tested it yet but thanks for response > > > > > -- > > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > 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.-- 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.