removed show method from controller yet show page is still present. why?

24 views
Skip to first unread message

Bizt

unread,
Feb 1, 2014, 8:18:44 PM2/1/14
to rubyonra...@googlegroups.com
I used "rails generate scaffold ..." to build my model, views and controllers. However for this particular MVC I don't want to have a show template. So, I removed the show method from the controller. But, show still appears. Why is this. Does ApplicationController have a show method? Is the only means to do this by deleting the show template? thanks

Hassan Schroeder

unread,
Feb 1, 2014, 8:46:41 PM2/1/14
to rubyonrails-talk
On Sat, Feb 1, 2014 at 5:18 PM, Bizt <marty...@gmail.com> wrote:
> I used "rails generate scaffold ..." to build my model, views and
> controllers. However for this particular MVC I don't want to have a show
> template. So, I removed the show method from the controller. But, show still
> appears. Why is this.

What does `rake routes` tell you? Compare that to config/routes.rb.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Bizt

unread,
Feb 1, 2014, 9:30:09 PM2/1/14
to rubyonra...@googlegroups.com
Yes, it must be in routes. I forgot. In config/routes.rb it seems to be handle with:

resources :accounts

In the documentation it seems I can specify which methods I want to allow:

resources :accounts, only: [:index, :new, :create, :edit, :update, :destroy] # no show

is this the correct/ best way to restrict access? Then I can delete my controller method ad view(?)

Hassan Schroeder

unread,
Feb 1, 2014, 10:30:56 PM2/1/14
to rubyonrails-talk
On Sat, Feb 1, 2014 at 6:30 PM, Bizt <marty...@gmail.com> wrote:

> In the documentation it seems I can specify which methods I want to allow:
>
> resources :accounts, only: [:index, :new, :create, :edit, :update, :destroy]
> # no show
>
> is this the correct/ best way to restrict access?

You can also use

resources :accounts, except: [ :show ]

> Then I can delete my controller method ad view(?)

Sure. Or maybe. Do frequent git saves, try it, change your mind,
it's all good :-)

Guilherme Dallanol

unread,
Feb 2, 2014, 8:29:49 AM2/2/14
to rubyonra...@googlegroups.com
Hey guys, I just read why this is happening at The Rails 4 Way book:

"The goal of the typical controller action is to render a view template—that is, to fill out the template and hand the results, usually an HTML document, back to the server for delivery to the client. Oddly—at least it might strike you as a bit odd, though not illogical—you don’t actually need to define a controller action, as long as you’ve got a template that matches the action name."

So, try to delete the 'show' template for this controller and try again. :)
Reply all
Reply to author
Forward
0 new messages