LoginSignup
0
0

More than 5 years have passed since last update.

form_forのフォームヘルパーのpatch機能を活用 

Last updated at Posted at 2018-08-19

イベント管理システムを作成
rails view ファイルでデータへ編集画面を edit.html.erb で作成

event.html.erb
<%= form_for @event, url: "/events/#{@event.id}" do |f| %>
<%= f.label :タイトル %><br>
<%= f.text_field :title %>
・
・
<% end %>
<%= f.submit value:"登録" %>

※f.text_field :titleの中にはデータは入ってます。

登録を押したら   
routeのpatch機能を利用して
events_controller のupdateアクションに移るよう作成を試みる

試行錯誤の結果
config/route.rbファイルに下記を追加したら
どうにか動くようになりました。

config/route.rb
resources :events, :only => :update

なぜ、 formヘルパーにこだわるかと言えば、
チェック機能等便利な仕組みがあるからです。

参考にしたサイト

マイブログ
https://blooming-reef-85835.herokuapp.com/posts/index

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0