Rails:nil的未定义方法`model_name’:NilClass

如何创建单独的页面,同时仍能从控制器和模型中获取用户信息?

例如,我想拥有单独的页面,但仍然使用产品控制器中的相同信息。

views / product / order.html.erb

然而,当我添加一个simple_form_for时,我得到一个错误

 

基本上我想要的是一个提交产品信息的separte页面。 如果不是,我很乐意在同一页面内做到这一点并拥有像这样的旋转simple_form,而无需创建多个页面。

http://malsup.com/jquery/cycle/

例:

实施例-1实施例-2实施例-3

products_controller.rb

 class ProductsController < ApplicationController before_action :set_product, only: [:show, :edit, :update, :destroy] def index @products = Product.where(availability: true) respond_with(@products) end def show end def new @product = Product.new end def edit authorize! :manage, @product end def create @product = current_user.products.new(product_params) @product.save respond_with(@product) end def update authorize! :manage, @product respond_to do |format| if @product.update(product_params) format.html { redirect_to @product, notice: 'Product was successfully updated.' } format.json { render :show, status: :ok, location: @product } else format.html { render :edit } format.json { render json: @product.errors, status: :unprocessable_entity } end end end def destroy authorize! :manage, @product @product.destroy respond_to do |format| format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } format.json { head :no_content } end end 

 <%= simple_form_for(@product) do |f| %> 

使用@product代替@products

将以下内容添加到products_controller.rb中

 def order @product = Product.new end