简体   繁体   中英

Rails 3 - Redirect_to / Render another controller

I have 2 controllers: Projects and Users . Both models have no relation at all.

When I create a new Project I want to redirect to the new User path after saving the new project , but all my tries give erros like missing template or stuff like that.

How can I get this working?

EDITED

My create method in Projects controller:

def create

@project = Project.new(params[:project])

respond_to do |format|
  if @project.save     
    format.html { render (new_user_registration_path) }

  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @project.errors, :status => :unprocessable_entity }
  end
end

end

您不想呈现new_user_registration_path,您想重定向到new_user_registration_path

you must use redirect_to instead render:

 redirect_to new_user_registration_path

 respond_to do |format|
   if @project.save     
     format.html { redirect_to new_user_registration_path }
   else
     format.html { render :action => "new" }
     format.xml  { render :xml => @project.errors, :status => :unprocessable_entity }
   end
 end

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