Hi I am pretty new to rails and mvc, but my application has users and I want to allow someone to quickly sign up from the home page using a bootstrap modal and to allow them to sign up through a normal sign up page.
In my Users controller I have created a partial for the modal _newUserModal.html.erb
and I want to use this in the index action from my Home controller.
I have read that I should load partials from another controller inside the action. So I am trying the following
class HomeController < ApplicationController
def index
render 'users/newUserModal'
end
end
This is giving me the error
Template is missing
Missing template users/newUserModal with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/jeff/Development/iHaul/app/views" * "/home/jeff/Development/iHaul" * "/"
I have a feeling I am missing something small but I can't figure it out.
Ok by moving the render to the bottom of my home.html.erb it has allowed my code to work. I know this isn't the best practice but it works for now. If anyone can shed some light on the issue that would help a lot.
My advice for anyone who is using partials from another controller is do not give a partial the same name as a method. If you do you have to specifically tell render to use the partial file with
render :partial => 'controller/action'
if your careful render works normally, although the above is more readable.
OK my remaining question is wrong. After a nights sleep I realized I am not using the MVC pattern for what it is designed for. I was being to precious with using @user = User.new . If I just use that in the index function of my home controller everything works beautifully.
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.