我一直在這個問題上停留了一段時間,並且在解決方案後搜索瞭解決方案,到目前爲止,我遇到的問題都無法解決。rails param丟失或者值爲空:post
我爲我的應用程序創建了一個新的對象的導軌腳手架,我設置了表格,並在運行服務器時查看Post對象。
,當我去查看時,我的服務器運行後對象的問題,它的內容不顯示,我不能更新這個錯誤被拋出的對象:數據庫長相
param is missing or the value is empty: post
的Posts table
像這樣:
正如你可以看到,現場content
有我想要顯示我的網頁上,當我去查看後說的數據。
這是出現相反:
what i see when running the server
,你可以看到,它不會顯示content
字段的內容。
這是我posts_controller.rb
class PostsController < ApplicationController
# you may want to udpate these posts? typo's outdated info?
before_action :set_post, only: [:show, :edit, :update, :destroy]
# GET /posts
# GET /posts.json
def index
@posts = Post.all
end
# GET /posts/1
# GET /posts/1.json
def show
end
# GET /posts/new
def new
@post = Post.new
end
# GET /posts/1/edit
def edit
end
# POST /posts
# POST /posts.json
def create
@post = Post.new(post_params)
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render action: 'show', status: :created, location: @post }
else
format.html { render action: 'new' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /posts/1
# PATCH/PUT /posts/1.json
def update
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
@post.destroy
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
params.require(:post).permit(:content)
end
end
我認爲這將讓我看到了content
def post_params
params.require(:post).permit(:content)
end
,我想這是什麼定義before_action :set_post, only: [:show, :edit, :update, :destroy]
的:post
因爲
def set_post
@post = Post.find(params[:id])
end
這是什麼 顯示錯誤頁面上軌:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"tHFQAWv08aUoi7ndZsVC1aCNJkYP6hE8w+89NTTpBjc=",
"commit"=>"Update Post",
"id"=>"2"}
我真的很困惑,爲什麼發生這種情況,進出口新的軌道,從而毫無疑問我在想念着一些基本的東西。
謝謝, 克里斯。
你可以把你的html代碼,因爲那是我認爲的問題是 – 2014-11-06 00:50:51
@OmarMowafi現在沒有必要!你提到這讓我記得我需要更新html,所以謝謝! – 2014-11-06 01:07:37
不客氣。我認爲你應該關閉這個問題,或者用你失去的東西來更新它。 – 2014-11-06 01:12:28