SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Marin CA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wrong number of arguments (0 for 1)

    I am getting a error I can't quite understand:
    ArgumentError in FoodsController#create
    wrong number of arguments (0 for 1)

    here is the create code in my FoodsController:

    def create
    @food = Food.new(params[:food])

    respond_to do |format|
    if @food.save
    flash[:notice] = 'Food was successfully created.'
    format.html { redirect_to(@food) }
    format.xml { render ml => @food, :status => :created, :location => @food }
    else
    format.html { render :action => "new" }
    format.xml { render ml => @food.errors, :status => :unprocessable_entity }
    end
    end
    end
    Any direction would be great. Many thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,140
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    My guess is that params[:food] is empty or null.

    Maybe that should be
    @food - Food.new

    and then in a "create", "build" the parameter? Similar to
    Code Ruby:
    ...
      def new
        @story = Story.new
      end
     
      def create
        @story = @current_user.stories.build params[:story]
        @story.save
        if @story.save
          flash[:notice] = 'Story submission succeeded'
          redirect_to stories_path
        else
          render :action => 'new'
        end      
      end

    BTW, please use the bbcode tags for your code examples or at least turn off smilies


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •