レールで足場を使用すると、コントローラーは次のようなさまざまなメソッドを作成します
新規、作成、表示、索引など
しかし、ここではアクションを作成するための新しいアクションの遷移を理解できません
例えば。新しい投稿をクリックすると、新しいアクションが検索され、_form がレンダリングされますが、送信時にデータがその特定のテーブルにどのように入力されたか、コントローラーの作成アクションが呼び出された場所と方法は?
私のposts_controllerは
def new
@post = Post.new
@post.user_id = current_user.id
@post.save
respond_to do |format|
format.html # new.html.erb
format.json { render json: @post }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
authorize! :manage, @post
end
# POST /posts
# POST /posts.json
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end