简体   繁体   中英

Rails Model and Controller

I generated a controller called Search. later I built a model called search as well. When i try to make a search i get an error that says there is no controller called searches, so it looks like it the model interacts with the plural of itself by default. how do i change this behaviour

Sounds like you are quite new to rails. The best advice here is almost certainly "don't" Rails uses a lot of conventions to avoid having to configure everything, and this is one of them. So I would recommend changing the name of your controller rather than trying to make rails do something out of the ordinary

for more detail see this stackoverflow question

Just rename the controller class from 'SearchController' to 'SearchesController'. Also rename the file in apps/controllers to from search_controller.rb to searches_controller.rb .

When you have generated controller and model separately, you also generated additional files like test files, views and so on. So potentially you will have big headache on this.

I would recommend to use rails destroy command in these steps:

Commit your current project (later you can recover your content from it)

Run this commands:

rails destroy model Search
rails destroy controller Search

Restore your controller and model from previous commit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM