実現したいこと
createアクションを実行した後、直接editページへ遷移するようにする。
方法
データをcreateアクションからredirect_toを使ってeditページへ直接遷移させたいのですが、そのままだと、エラーになります。
def create
redirect_to edit_lineproduction_path
endエラーになる原因は、データをcreateした時点ではidが割り振られていないので、id=nillとなり、ページ遷移できません。
そこで、以下のようにすると、idを取得でき、editページへ遷移するようになります。
def create
production = Production.create(production_params)
redirect_to edit_line_production_path(id: production.id)
endただし、editページに遷移するのに、idが複数必要なときは、それぞれきちんと指定してあげないといけません。この場合、line_idとproduction_idが必要です。
def create
production = Production.create(production_params)
redirect_to edit_line_production_path(id: production.id, line_id: production.line_id)
endこれで、createが成功したら直接editページに飛ぶことができます。

