I have created a simple application and edited the index.erb file so that I have a simple view with a text box and a button.
Now when i click on that button i want it to navigate to a new view.
I know that we can add models and in that models we have different .erb files.
but i want to create a single .erb file or add it to an existing model so that i can change edit the view and call that view as i press the button.
Is it like for every screen we have to create a model??
I dont know how to do the same, i tried searching but no help so far.
It is not that for every screen you’ve to create a model rather the reverse. Every model for which you need interfaces you’ll create views.
Why don’t you start with this guide and move ahead understanding the basics.
Other than CRUD interfaces? You can add a view file directly to the view folder of the controller this model is associated with. For example, if the model is post.rb in
app/modelsand it has a corresponding controllerposts_controller.rbinapp/controllersand it has corresponding views inapp/views/poststhen you can add your view toapp/views/postsfolder with a corresponding method in the controller which will render that view provided there is a route for that in theconfig/routes.rbfile.Say I want to add a
landing_page.html.erbview to Post. I would add a method inposts_controller.rb(although, this is not mandatory. But, might be useful for you to check some conditions before rendering the view):Add a view in app/views/posts directory:
Add a route to the config/routes.rb file:
Now, you can access the page at
http://localhost:3000/posts/:id/landing_page.