Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty (but working) show method on controller generated via scaffolding?

How is that the show method on a controller class generated via rails generate scaffold xxx empty / contains no code? Where is the code for showing individual records via URL e.g. /my_rails_app:3000/xxx/1 stored?

The method should, at the very least, looks like this IMO:

class ProductController
  # GET /students/1
  # GET /students/1.json
  def show
    @item = Product.find(params[:id])
    render @item
  end
end

but instead it is completely empty:

class ProductController
  # GET /students/1
  # GET /students/1.json
  def show

  end
end
like image 634
lolski Avatar asked Jan 10 '14 09:01

lolski


People also ask

How do I add a scaffold to a controller?

To add a scaffold, right-click on Controllers folder in the Solution Explorer and select Add → New Scaffolded Item. It will display the Add Scaffold dialog.

How to build a solution with a scaffold in Visual Studio?

Now let’s build a solution and you will see the message when the project is successfully build. To add a scaffold, right-click on Controllers folder in the Solution Explorer and select Add → New Scaffolded Item. It will display the Add Scaffold dialog.

What is scaffolding in MVC?

Here we will learn what is scaffolding in asp.net mvc and types of controller scaffoldings in asp.net mvc. Scaffolding is a technique used in asp.net mvc to generate basic CRUD operation (Create, Delete, Details, Edit, and List) from Model,.

What is scaffolding in autoa and how does it work?

A feature called Scaffolding creates a Controller and several Views on basis of a model. How does this feature work and how can we tell Visual Studio to generate the desired code for us? I’m going to tell you about it in this post.


1 Answers

If you are using rails 4 then there should have some before action method which is doing the magic for you please check in the respective controller.

It should be like before_action :set_product, :only => [:show, :edit, :update, :destroy]

like image 179
Sabyasachi Ghosh Avatar answered Nov 17 '22 15:11

Sabyasachi Ghosh