Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 报价中的NoMethod错误#显示_Mysql_Ruby On Rails_Ruby - Fatal编程技术网

Mysql 报价中的NoMethod错误#显示

Mysql 报价中的NoMethod错误#显示,mysql,ruby-on-rails,ruby,Mysql,Ruby On Rails,Ruby,我正在尝试为产品及其提供的服务创建一个rails应用程序。我已经创建了一个产品页面,通过该页面可以创建产品。该页面工作正常。但当我尝试为相应的产品创建报价页面并将其重定向到列表页面时,它会显示“报价中的NoMethodError” 显示/Users/smita/workspace/products/app/views/offers/show.html.erb,其中第9行出现: nil:NilClass的未定义方法'offer_name' 我正在使用rails 4、ruby 2.2.3和mysql

我正在尝试为产品及其提供的服务创建一个rails应用程序。我已经创建了一个产品页面,通过该页面可以创建产品。该页面工作正常。但当我尝试为相应的产品创建报价页面并将其重定向到列表页面时,它会显示“报价中的NoMethodError” 显示/Users/smita/workspace/products/app/views/offers/show.html.erb,其中第9行出现:

nil:NilClass的未定义方法'offer_name'

我正在使用rails 4、ruby 2.2.3和mysql数据库

这是我的密码:

产品\u控制器.rb

class ProductsController < ApplicationController
  def index     
      @product = Product.all
  end

  def list
      @products = Product.order("products.product_name ASC")
  end

  def show
      @product = Product.find(params[:id])
  end

  def new
      @product = Product.new
  end

    def create
    # Instantiate a new object using form parameters
        @product = Product.new(products_params)
    # Save the object
        if @product.save
      # If save succeeds, redirect to the list action
        redirect_to(:action => 'list')
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

    def delete
        @product = Product.find(params[:id]).destroy
    respond_to do |format|
      format.html { redirect_to :action => 'list', notice: 'User was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

    private
    def products_params
        params.require(:product).permit(:product_name, :product_desc, :product_image, :product_rate)
  end 
end
class OffersController < ApplicationController
   def index 
       @offer = Offer.all   
   end
  def list
      @offers = Offer.order("offers.offer_name ASC")
  end

  def show
      @offer = Offer.find_by_id(params[:id])
  end

  def new
      @offer = Offer.new
  end

    def create
    # Instantiate a new object using form parameters
        @offer = Offer.new(offers_params)
    # Save the object
        if @offer.save
      # If save succeeds, redirect to the list action
            redirect_to(:action => 'list', notice: 'offer was successfully created.' )
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

    def delete
        @offer = Offer.find(params[:id]).destroy
    respond_to do |format|
      format.html { redirect_to :action => 'list', notice: 'User was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

    private
    def offers_params
        params.require(:offer).permit(:product_id, :offer_name, :offer_start_date, :offer_end_date, :offer_description)
  end 
end
class ProductsController'list')
其他的
#如果保存失败,请重新显示表单,以便用户可以修复问题
呈现('新')
结束
结束
def删除
@product=product.find(params[:id]).destroy
回应待办事项|格式|
format.html{redirect_to:action=>“list”,注意:“用户已成功销毁”。}
format.json{head:no_content}
结束
结束
私有的
def产品参数
参数要求(:产品)。许可(:产品名称,:产品描述,:产品图片,:产品价格)
结束
结束
product.rb

class Product < ActiveRecord::Base
    has_many :offers
end
类产品
创造产品

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
        t.string "product_name"
        t.string "product_desc"
        t.string "product_image"
        t.integer "product_rate"
      t.timestamps null: false
    end
  end
end
class CreateProducts
products/list.html.erb

<div>
  <h2>Products</h2>

    <%= link_to("Add New Product", {:action => 'new'}) %>

  <table>
    <tr>
      <th>Product Id</th>
      <th>Product Name</th>
      <th>Product Desc</th>
      <th>Product Image</th>
      <th>Product Rate</th>
    </tr>
      <% @products.each do |product| %>
    <tr>
        <td><%= product.id %></td>
      <td><%= product.product_name %></td>
      <td><%= product.product_desc%></td>
      <td><%= product.product_image%></td>
      <td><%= product.product_rate %></td>
      <td>
          <%= link_to("Show", {:action => 'show', :id => product.id}) %>
          <%= link_to("Edit", {:action => 'edit', :id => product.id}) %>
          <%= link_to("Delete", {:action => 'delete', :id => product.id}, data: { confirm: 'Are you sure you want to delete this entry ?' }) %>
      </td>
    </tr>
    <% end %>
  </table>
</div>
<div>
  <h2>Offers !!!</h2>

    <%= link_to("Add new offers", {:action => 'new'}) %>

  <table>
    <tr>
      <th>Product Id</th>
      <th>Offer Id</th>
      <th>Offer Name</th>
      <th>Offer start date</th>
      <th>Offer start date</th>
      <th>Offer description</th>
    </tr>
      <% @offers.each do |offer| %>
    <tr>
        <td><%= offer.id %></td>
        <td><%= offer.offer_name %></td>
        <td><%= offer.offer_start_date %></td>
        <td><%= offer.offer_end_date %></td>
        <td><%= offer.offer_description %></td>
      <td>
          <%= link_to("Show", {:action => 'show', :id => offer.id}) %>
          <%= link_to("Edit", {:action => 'edit', :id => offer.id}) %>
          <%= link_to("Delete", {:action => 'delete', :id => offer.id}, data: { confirm: 'Are you sure you want to delete this entry ?' }) %>
      </td>
    </tr>
    <% end %>
  </table>
</div>

产品
'新'})%>
产品Id
品名
产品说明
产品形象
产品价格
'show',:id=>product.id})%>
'编辑',:id=>product.id})%>
'delete',:id=>product.id},数据:{confirm:'确实要删除此条目吗?'})%>
products/new.html.erb

<div>
  <h2>Create Product</h2>

    <%= form_for Product.new ,:url => {:action => :create, :controller => :products} do |f| %>

    <table>
      <tr>
        <th>Product Name</th>
          <td><%= f.text_field(:product_name) %></td>
      </tr>
      <tr>
        <th>Product Desc</th>
          <td><%= f.text_field(:product_desc) %></td>
      </tr>
      <tr>
        <th>Product Image</th>
        <td><%= f.text_field(:product_image) %></td>
      </tr>
        <tr>
        <th>Product Rate</th>
            <td><%= f.text_field(:product_rate) %></td>
      </tr>
    </table>

    <div>
        <%= submit_tag("Save Product") %>
    </div>

  <% end %>
</div>

创造产品
{:action=>:create,:controller=>:products}do | f |%>
品名
产品说明
产品形象
产品价格
products/show.html.erb

<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show Product</h2>

  <table>
    <tr>
      <th>Product Name</th>
        <td><%= @product.product_name %></td>
    </tr>
    <tr>
      <th>Product Desc</th>
      <td><%= @product.product_desc %></td>
    </tr>
    <tr>
      <th>Product Image</th>
        <td><%= @product.product_image %></td>
    </tr>
    <tr>
      <th>Product Rate</th>
        <td><%= @product.product_rate%></td>
    </tr>

  </table>

</div>
<div>
  <h2>New Offers</h2>

    <%= form_for Offer.new ,:url => {:action => :create, :controller => :offers} do |f| %>

    <table>
      <tr>
        <th>Offer Name</th>
          <td><%= f.text_field(:offer_name) %></td>
      </tr>
      <tr>
        <th>Offer start date</th>
          <td><%= f.text_field(:offer_start_date) %></td>
      </tr>
      <tr>
        <th>Offer end date</th>
          <td><%= f.text_field(:offer_end_date) %></td>
      </tr>
        <tr>
        <th>Offer description</th>
            <td><%= f.text_field(:offer_description) %></td>
      </tr>
    </table>

    <div>
        <%= submit_tag("Save offer") %>
    </div>

  <% end %>
</div>
<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show offers</h2>

  <table>
    <tr>
      <th>Offer Name</th>
        <td><%= @offer.offer_name %></td>
    </tr>
    <tr>
      <th>Offer start date</th>
        <td><%= @offer.offer_start_date %></td>
    </tr>
    <tr>
      <th>Offer end date</th>
        <td><%= @offer.offer_end_date %></td>
    </tr>
    <tr>
      <th>Offer description</th>
        <td><%= @offer.offer_description %></td>
    </tr>

  </table>

</div>
'list'})%>
展示产品
品名
产品说明
产品形象
产品价格
提供_controller.rb

class ProductsController < ApplicationController
  def index     
      @product = Product.all
  end

  def list
      @products = Product.order("products.product_name ASC")
  end

  def show
      @product = Product.find(params[:id])
  end

  def new
      @product = Product.new
  end

    def create
    # Instantiate a new object using form parameters
        @product = Product.new(products_params)
    # Save the object
        if @product.save
      # If save succeeds, redirect to the list action
        redirect_to(:action => 'list')
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

    def delete
        @product = Product.find(params[:id]).destroy
    respond_to do |format|
      format.html { redirect_to :action => 'list', notice: 'User was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

    private
    def products_params
        params.require(:product).permit(:product_name, :product_desc, :product_image, :product_rate)
  end 
end
class OffersController < ApplicationController
   def index 
       @offer = Offer.all   
   end
  def list
      @offers = Offer.order("offers.offer_name ASC")
  end

  def show
      @offer = Offer.find_by_id(params[:id])
  end

  def new
      @offer = Offer.new
  end

    def create
    # Instantiate a new object using form parameters
        @offer = Offer.new(offers_params)
    # Save the object
        if @offer.save
      # If save succeeds, redirect to the list action
            redirect_to(:action => 'list', notice: 'offer was successfully created.' )
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

    def delete
        @offer = Offer.find(params[:id]).destroy
    respond_to do |format|
      format.html { redirect_to :action => 'list', notice: 'User was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

    private
    def offers_params
        params.require(:offer).permit(:product_id, :offer_name, :offer_start_date, :offer_end_date, :offer_description)
  end 
end
class-OffersController'list',注意:'offer已成功创建')
其他的
#如果保存失败,请重新显示表单,以便用户可以修复问题
呈现('新')
结束
结束
def删除
@offer=offer.find(params[:id]).destroy
回应待办事项|格式|
format.html{redirect_to:action=>“list”,注意:“用户已成功销毁”。}
format.json{head:no_content}
结束
结束
私有的
def提供_参数
参数require(:offer).permit(:产品id,:offer\u名称,:offer\u开始日期,:offer\u结束日期,:offer\u描述)
结束
结束
offer.rb

class Offer < ActiveRecord::Base

    belongs_to :offers
    accepts_nested_attributes_for :offers
end
class Offer
CreateOffers

class CreateOffers < ActiveRecord::Migration
  def change
    create_table :offers do |t|
        t.string "product_id"
        t.string "offer_name"
        t.string "offer_start_date"
        t.string "offer_end_date"
        t.string "offer_description"
      t.timestamps null: false
    end
  end
end
class CreateOffers
offer/list.html.erb

<div>
  <h2>Products</h2>

    <%= link_to("Add New Product", {:action => 'new'}) %>

  <table>
    <tr>
      <th>Product Id</th>
      <th>Product Name</th>
      <th>Product Desc</th>
      <th>Product Image</th>
      <th>Product Rate</th>
    </tr>
      <% @products.each do |product| %>
    <tr>
        <td><%= product.id %></td>
      <td><%= product.product_name %></td>
      <td><%= product.product_desc%></td>
      <td><%= product.product_image%></td>
      <td><%= product.product_rate %></td>
      <td>
          <%= link_to("Show", {:action => 'show', :id => product.id}) %>
          <%= link_to("Edit", {:action => 'edit', :id => product.id}) %>
          <%= link_to("Delete", {:action => 'delete', :id => product.id}, data: { confirm: 'Are you sure you want to delete this entry ?' }) %>
      </td>
    </tr>
    <% end %>
  </table>
</div>
<div>
  <h2>Offers !!!</h2>

    <%= link_to("Add new offers", {:action => 'new'}) %>

  <table>
    <tr>
      <th>Product Id</th>
      <th>Offer Id</th>
      <th>Offer Name</th>
      <th>Offer start date</th>
      <th>Offer start date</th>
      <th>Offer description</th>
    </tr>
      <% @offers.each do |offer| %>
    <tr>
        <td><%= offer.id %></td>
        <td><%= offer.offer_name %></td>
        <td><%= offer.offer_start_date %></td>
        <td><%= offer.offer_end_date %></td>
        <td><%= offer.offer_description %></td>
      <td>
          <%= link_to("Show", {:action => 'show', :id => offer.id}) %>
          <%= link_to("Edit", {:action => 'edit', :id => offer.id}) %>
          <%= link_to("Delete", {:action => 'delete', :id => offer.id}, data: { confirm: 'Are you sure you want to delete this entry ?' }) %>
      </td>
    </tr>
    <% end %>
  </table>
</div>

提供!!!
'新'})%>
产品Id
报价Id
报盘名称
报价开始日期
报价开始日期
报价说明
'show',:id=>offer.id})%>
'编辑',:id=>offer.id})%>
'delete',:id=>offer.id},数据:{confirm:'确实要删除此条目吗?'})%>
offer/new.html.erb

<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show Product</h2>

  <table>
    <tr>
      <th>Product Name</th>
        <td><%= @product.product_name %></td>
    </tr>
    <tr>
      <th>Product Desc</th>
      <td><%= @product.product_desc %></td>
    </tr>
    <tr>
      <th>Product Image</th>
        <td><%= @product.product_image %></td>
    </tr>
    <tr>
      <th>Product Rate</th>
        <td><%= @product.product_rate%></td>
    </tr>

  </table>

</div>
<div>
  <h2>New Offers</h2>

    <%= form_for Offer.new ,:url => {:action => :create, :controller => :offers} do |f| %>

    <table>
      <tr>
        <th>Offer Name</th>
          <td><%= f.text_field(:offer_name) %></td>
      </tr>
      <tr>
        <th>Offer start date</th>
          <td><%= f.text_field(:offer_start_date) %></td>
      </tr>
      <tr>
        <th>Offer end date</th>
          <td><%= f.text_field(:offer_end_date) %></td>
      </tr>
        <tr>
        <th>Offer description</th>
            <td><%= f.text_field(:offer_description) %></td>
      </tr>
    </table>

    <div>
        <%= submit_tag("Save offer") %>
    </div>

  <% end %>
</div>
<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show offers</h2>

  <table>
    <tr>
      <th>Offer Name</th>
        <td><%= @offer.offer_name %></td>
    </tr>
    <tr>
      <th>Offer start date</th>
        <td><%= @offer.offer_start_date %></td>
    </tr>
    <tr>
      <th>Offer end date</th>
        <td><%= @offer.offer_end_date %></td>
    </tr>
    <tr>
      <th>Offer description</th>
        <td><%= @offer.offer_description %></td>
    </tr>

  </table>

</div>

新报价
{:action=>:create,:controller=>:offers}do | f |%>
报盘名称
报价开始日期
报价截止日期
报价说明
offer/show.html.erb

<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show Product</h2>

  <table>
    <tr>
      <th>Product Name</th>
        <td><%= @product.product_name %></td>
    </tr>
    <tr>
      <th>Product Desc</th>
      <td><%= @product.product_desc %></td>
    </tr>
    <tr>
      <th>Product Image</th>
        <td><%= @product.product_image %></td>
    </tr>
    <tr>
      <th>Product Rate</th>
        <td><%= @product.product_rate%></td>
    </tr>

  </table>

</div>
<div>
  <h2>New Offers</h2>

    <%= form_for Offer.new ,:url => {:action => :create, :controller => :offers} do |f| %>

    <table>
      <tr>
        <th>Offer Name</th>
          <td><%= f.text_field(:offer_name) %></td>
      </tr>
      <tr>
        <th>Offer start date</th>
          <td><%= f.text_field(:offer_start_date) %></td>
      </tr>
      <tr>
        <th>Offer end date</th>
          <td><%= f.text_field(:offer_end_date) %></td>
      </tr>
        <tr>
        <th>Offer description</th>
            <td><%= f.text_field(:offer_description) %></td>
      </tr>
    </table>

    <div>
        <%= submit_tag("Save offer") %>
    </div>

  <% end %>
</div>
<%= link_to("<< Back to List", {:action => 'list'}) %>

<div>
  <h2>Show offers</h2>

  <table>
    <tr>
      <th>Offer Name</th>
        <td><%= @offer.offer_name %></td>
    </tr>
    <tr>
      <th>Offer start date</th>
        <td><%= @offer.offer_start_date %></td>
    </tr>
    <tr>
      <th>Offer end date</th>
        <td><%= @offer.offer_end_date %></td>
    </tr>
    <tr>
      <th>Offer description</th>
        <td><%= @offer.offer_description %></td>
    </tr>

  </table>

</div>
'list'})%>
演出邀请
报盘名称
报价开始日期
报价截止日期
报价说明

请告诉我哪里出了问题。提前谢谢

您应该更改设置,以便在单击某个产品时获得报价索引。您可以通过以下方式完成:

这将允许您“确定”围绕
pro的报价流程