質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

1回答

1282閲覧

レンダーファイル、form_forのurl先がわかりません。

Marge0101

総合スコア15

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

0クリップ

投稿2017/12/13 00:12

下記エラーがでてしまいました。new とeditで同じフォームをしようしている場合はurlを指定するときいたのですが、正しい先がわかりません。
初歩的なものなのですがどうしてもわからずこまっています。

どうぞよろしくお願い致します。

イメージ説明

Ruby on rails 4

【現在の内容】

routes

Rails.application.routes.draw do resources :recipes root 'recipes#index' get 'recipes/index' end <rake routesにて確認しましたがいまいち見方になれておらず、 どのように指定したらよいのか迷っています。> Prefix Verb URI Pattern Controller#Action recipes GET /recipes(.:format) recipes#index POST /recipes(.:format) recipes#create new_recipe GET /recipes/new(.:format) recipes#new edit_recipe GET /recipes/:id/edit(.:format) recipes#edit recipe GET /recipes/:id(.:format) recipes#show PATCH /recipes/:id(.:format) recipes#update PUT /recipes/:id(.:format) recipes#update DELETE /recipes/:id(.:format) recipes#destroy root GET / recipes#index recipes_index GET /recipes/index(.:format) recipes#index

controller

def create @recipe = Recipe.new(recipe_params) if @recipe.save redirect_to @recipe, notice:"Successfully created new recipe" else render 'new' end end def edit end def update if @recipe.updte(recipe_params) redirect_to @recipe else render 'edit' end end def destroy @recipe.destroy redirect_to root_path, notice:"Successfully deleted recipe" end private def recipe_params params.require(:recipe).permit(:title, :description) end def find_recipe @recipe = Recipe.find(params[:id]) end end

Edit

<h1>Edit Recipe</h1> <%=render 'form'%>

new

<h1>New Recipe</h1> <%=render'form'%> <br> <%=link_to"Back",root_path, class:"btn btn-default"%>

model

class Recipe < ActiveRecord::Base end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

どのURLをnewとeditを兼用したフォームにしたいとお考えですか?

投稿2017/12/13 01:10

kenny_sayama

総合スコア1036

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Marge0101

2017/12/13 06:19

ご返答ありがとうございます。 ../recipes/new と../recipes/id/editのページに”_form.html.erb"のファイルをrenderで入れたいです。 view のnew、createアクションは作動するのですが、show ページからeditボタンを押すとエラーが出てしまいます。 form_forの書き方が間違えているのですが、editページに表示させる方法がわかりません。 どうぞよろしくお願い致します
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問