Forum: Ruby on Rails custom REST action - template question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pavel Krusek (Guest)
on 2008-12-14 15:55
(Received via mailing list)
Hallo phorum,

i have custom rest action.

routes.rb:
map.resources :schools, :collection => { :graduations => :get }

SchoolsController:
def graduations
  @schools = School.graduation(true)
end

link somewhere in navigation:
<%= link_to 'Schools with graduation', graduations_schools_path %>


All works OK for me, but Rails needs (of course) a template for
controller action 'graduations':

Template is missing

Missing template schools/graduations.erb in view path blah blah blah...

But i need to use the template 'index.html.erb' instead of the new
template 'graduations.html.erb'...

How to do this in Schools controller?
thanks,

--
Pavel Krusek

removed_email_address@domain.invalid
Petr B. (Guest)
on 2008-12-14 17:18
Pavel Krusek wrote:
> Hallo phorum,
>
> i have custom rest action.
>
> routes.rb:
> map.resources :schools, :collection => { :graduations => :get }
>
> SchoolsController:
> def graduations
>   @schools = School.graduation(true)
> end
>
> link somewhere in navigation:
> <%= link_to 'Schools with graduation', graduations_schools_path %>
>
>
> All works OK for me, but Rails needs (of course) a template for
> controller action 'graduations':
>
> Template is missing
>
> Missing template schools/graduations.erb in view path blah blah blah...
>
> But i need to use the template 'index.html.erb' instead of the new
> template 'graduations.html.erb'...
>
> How to do this in Schools controller?
> thanks,
>
> --
> Pavel Krusek
>
> removed_email_address@domain.invalid

class SchoolsController:
layout 'mynewlayout'

def graduations
end
.
.

And it will use your custom layout called mynewlayout


Hope this helps.
Petr ;)
(BTW: čus)
Pavel Krusek (Guest)
on 2008-12-14 18:02
(Received via mailing list)
Hi,

i thought the template for concrete action 'graduations', no template
for layout.

Solution:

def graduations
   @schools = School.graduation(true)
   render :action => "index"
 end

I forgot direction 'render' ;)

Thanks,

Pavel

Zdar :)



2008/12/14 Petr B. <removed_email_address@domain.invalid>:
>> def graduations
>> Template is missing
>> Pavel Krusek
>
>
--
Pavel Krusek

+420 602 641 039
irb(main):001:0> ( 'pavel.krusekATgmail._see_om'.gsub('_see_',
'c').gsub('AT', '@') )
This topic is locked and can not be replied to.