mardi 10 novembre 2015

Ruby on Rails won't render edit page without id

For some reason the edit action won't render i get this error and is using show action instead of edit but the same form works for the render :new action

  • do not focus on the params[:preview], i am talking about the last render :edit

ActionController::UrlGenerationError in Admin::Blog::Posts#update No route matches {:action=>"show", :controller=>"admin/blog/posts", :id=>""} missing required keys: [:id]

def edit
    @post = Post.find_by_permalink(params[:id])
  end

def update
    @post = Post.find_by_permalink(params[:id])
    if params[:publish]
      @post.publish
    elsif params[:draft]
      @post.draft
    end

    if params[:preview]
      if @post.published?
        @post.draft
      end

      if @post.update(blog_post_params)
        flash[:success] = "some text "

        redirect_to blog_post_url(@post)
      else
        render :edit
      end
    end
    if @post.update(blog_post_params)
      flash[:success] = "Post was successfully updated."
      redirect_to edit_admin_blog_post_url(@post)
    else
      render :edit
    end

  end

Aucun commentaire:

Enregistrer un commentaire