Ok, the problem is trying to render a form from a controller to create a new entry.. For that im calling the default form that comes with the scaffold creation I'm trying to make it like this:
<%= render :partial => 'contactos/form' %>
And im getting the following error
undefined method 'model_name' for NilClass:Class
Is there any way of just rendering from the view itself?
If there is not... Which parameters should I add to the controller?
Right now I just have following code:
Class DisplayController < ApplicationController
def index
@contactos = Contacto.all
end
end
*This is the view controller, not the one with the create update and edit functions from my scaffold
Ok, I've done a very large research but no answer can fix my problem. (This is the first time I ask something, sorry in advance for any mistake I could make)
There is an important difference between render and redirect_to: render will tell Rails what view it should use (with the same parameters you may have already sent) but redirect_to sends a new request to the browser.
By default, if you use the :text option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option.
Ruby on Rails Views Partials Partial templates (partials) are a way of breaking the rendering process into more manageable chunks. Partials allow you to extract pieces of code from your templates to separate files and also reuse them throughout your templates.
The problem is that the variable your are using in the form for your contact doesn't exist. The only variable you created in the index action is an array of all the contacts, but the form needs a single instance of a single contact.
Because you are making a new contact, you have to do something like this in the action index:
@contact = Contact.new
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With