0
<% @idea.each do |@idea| %>
  <div id="basic_details" class="idea-show-columns">
    <%= render :partial => '/ideas/idea_basic_show', :locals => {:idea => @idea} %>
    <%= render :partial => 'ideas/comments' %>
    <%= render :partial => 'ideas/mockups' %>
  </div>

  <div id="copy_details" class="idea-show-columns">
    <%= render :partial => 'ideas/ copy_show', :locals => {:idea => @idea} %>
  </div>

<% end %>

当我@关闭它时,它说“未使用参数'idea'”,我找不到合适的语法。

想法控制器

class IdeasController < ApplicationController

  def index
    respond_to do |format|
      if request.xhr?
        @ideas = Idea.select("sku, id").order(:sku)
      else
        if params[:search]
          @ideas = Idea.where("sku like '%#{params[:search]}%' or working_name like '%#
    {params[:search]}%' or product_name like '%#{params[:search]}%'").paginate(:page => 
    params[:page]).reload
        else
          @ideas = Idea.paginate(:page => params[:page]).reload
        end
      end
      format.html
      format.json {render json: @ideas.where("sku like ?", "%#{params[:q]}%") }
    end
  end

  def show
    @idea = Idea.find_by_permalink(params[:id])
  end

  def new
    @idea = Idea.new
  end

  def create
    @idea = Idea.new(new_idea_params)
    if @idea.save
      flash[:notice] = 'Idea created!'
      redirect_to ideas_url
    else
      render :new
    end
  end

  def edit
    @idea = Idea.find_by_permalink(params[:id])
  end

  def update
    @idea = Idea.find_by_permalink(params[:id])
    if request.xhr?
      if params[:comment]
        @idea.comments.create(:title => params[:comment][:title], :comment => params[:comment][:comment], :user_id => current_user.id)
      end
      if @idea.update_attributes(update_status_params)
        @success = true
      else
        @success = false
      end
    else
      if @idea.update_attributes(edit_idea_params)
        flash[:notice] = 'Idea updated!'
        redirect_to idea_url(params[:id])
      else
        render :edit
      end
    end
  end

  def destroy
    Idea.find_by_permalink(params[:id]).destroy
    flash[:success] = "Idea destroyed."
    redirect_to ideas_url
  end

  def generate_mockups
    idea = Idea.find_by_permalink(params[:id])
    begin
      idea.generate_mockups
    rescue Exception => e
      flash[:error] = "There was an error generating the mockups for #{idea.working_name}! # {e.message}"
    end
    flash[:notice] = "Successfully generated mockups for #{idea.working_name}"
    redirect_to idea_url(params[:id])
  end

  def signoff
    if current_user.has_overlord_access?
      if params[:idea_id]
        idea = Idea.find(params[:idea_id])
        idea.overlord_id = current_user.id
        idea.status = 'Ready To Publish'
        idea.save
        flash[:notice] = "#{current_user.full_name} just signed off on #{idea.sku}"
        redirect_to :action => :signoff
      end
      @ideas = Idea.awaiting_overlord_signoff.reload
      @idea = @ideas.first.reload
    else
      flash[:notice] = 'Sorry, you must have overlord access to sign off on ideas.'
      redirect_to ideas_path
    end
  end

  private

  def new_idea_params
    params.require(:idea).permit(:sku, :working_name, :working_description, :priority)
  end

  def update_status_params
    params.require(:idea).permit(:art_status, :copy_status)
  end

  def edit_idea_params
    (params[:idea][:color_ids] ||= []) unless !current_user.has_artist_access?
    (params[:idea][:imprintable_ids] ||= []) unless !current_user.has_copywriter_access?
    (params[:idea][:stores_ids] ||= []) unless !current_user.has_copywriter_access?
    (params[:idea][:taxonomies_ids] ||= []) unless !current_user.has_copywriter_access?

    params.require(:idea).permit(:sku, :working_name, :working_description, :priority,  
    :product_name, :product_line_tokens,
                                 :description, :meta_description, :meta_keywords, :artist_id, 
    :copywriter_id, :overlord_id,
                                  {:store_ids => []}, {:taxonomy_ids => []}, :base_price, 
    :shipping_category, :default_artwork_id,
                                  :tax_category, {:imprintable_ids => []}, :marketplace, 
    :product_type, 
                                  :base, :colors_offered, :special_instructions, :copy_status, 
    :art_status, {:color_ids => []}, 
                                  :artworks_attributes => [:height, :width, :from_top,    
    :from_center, :idea_id, :dimensions, :file, :_destroy, :id])
  end

  def update_status_params
    params.require(:idea).permit(:copy_status, :art_status)
  end
end

我收到错误

undefined method `each' for nil:NilClass
4

2 回答 2

3

它应该 :

<% unless @ideas.nil? %>

    <% @ideas.each do |idea| %>

        <div id="basic_details" class="idea-show-columns">
            <%= render :partial => '/ideas/idea_basic_show', :locals => {:idea => idea} %>
            <%= render :partial => 'ideas/comments' %>
            <%= render :partial => 'ideas/mockups' %>
        </div>

        <div id="copy_details" class="idea-show-columns">
            <%= render :partial => 'ideas/ copy_show', :locals => {:idea => idea} %>
        </div>

    <% end %>

<% end %>
于 2013-11-07T20:40:13.577 回答
0

一些事情:

  • 如果您需要在show视图中使用@ideas,则需要使用before_filter
  • 不要这样做,dea.where("sku like '%#{params[:search]}%'因为这不安全。做类似的事情where("code = ?", params[:code])
于 2013-11-07T21:16:43.593 回答