Shakes#index中的ArgumentError,nil不是有效的资产来源

时间:2016-11-29 19:03:56

标签: ruby-on-rails ruby

嗨,大家好,当我试图使用图像标签拉图像时,它给出的nil不是我的资产中的有效资源来源ive图像文件,奇怪的是这个问题只发生在iam尝试使用装饰图案时没有它图像正在显示,我对这个相当新,任何一位专家都能说清楚我做错了什么? 感谢

require 'shake_decorator'

class ShakesController < ApplicationController
  before_action :set_shake, only: [:show, :edit, :update, :destroy]

  # GET /shakes
  # GET /shakes.json
  def index
    @shakes = Shake.all
  end

  # GET /shakes/1
  # GET /shakes/1.json
  def show
  end

  # GET /shakes/new
  def new
    @shake = Shake.new
  end

  # GET /shakes/1/edit
  def edit
  end

  # POST /shakes
  # POST /shakes.json
  def create
  
     @shake = Shake.new()
     @shake.Name=params[:shake][:Name]
     @shake.Cost=params[:shake][:Cost]
     @shake.Calories=params[:shake][:Calories]
   
  
   # create an instance/object of a BasicCar
   


     myShake=BasicShake.new(@shake.Cost,@shake.Calories)


    #add the extra features to the new car
   if params[:shake][:caramel].to_s.length > 0 then
     myShake = CaramelDecorator.new(myShake)
   end
   if params[:shake][:pbutter].to_s.length > 0 then
     myShake = PeanutbutterDecorator.new(myShake)
   end
   if params[:shake][:cream].to_s.length > 0 then
     myShake = CreamDecorator.new(myShake)
   end
      #populate the cost and the description details
    @shake.Cost = myShake.cost
    @shake.description = myShake.details

     #retrieve the instance/object of the MyLogger class
  
 

       respond_to do |format|
      if @shake.save
        format.html { redirect_to @shake, notice: 'Shake was successfully created.' }
        format.json { render :show, status: :created, location: @shake }
      else
        format.html { render :new }
        format.json { render json: @shake.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /shakes/1
  # DELETE /shakes/1.json
  def destroy
    @shake.destroy
    respond_to do |format|
      format.html { redirect_to shakes_url, notice: 'Shake was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_shake
      @shake = Shake.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def shake_params
      params.require(:shake).permit(:Name, :Cost, :Calories, :image_url)
    end
end

<p id="notice"><%= notice %></p>

<h1>Shakes</h1>

<table border="2">
  <thead>
    <tr>
      <th>Name</th>
      <th>Cost</th>
      <th>Calories</th>
      <th>Image url</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @shakes.each do |shake| %>
      <tr>
        <td><%= shake.Name %></td>
        <td><%= shake.Cost %></td>
        <td><%= shake.Calories %></td>
           <td><%= image_tag(shake.image_url, :class => 'list_image' ,:style => "height:100px") %></td>

    


    
        <td><%= link_to 'Show', shake %></td>
        <td><%= link_to 'Edit', edit_shake_path(shake) %></td>
        <td><%= link_to 'Destroy', shake, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Shake', new_shake_path %>

0 个答案:

没有答案