バージョン情報
Rails 5.2.3
ruby 2.6.3p62
.
.
edit.html.erbです。
<div> <div class="col-md-4 offset-md-4"> <h2 class="text-center">Edit ポジティブ!</h2> <%= form_with modle: @positive ,local: true do |f| %> <div class ="form-group"> <label>Title</label> <%= f.text_field :title,class:"form-control" %> </div> <div class ="form-group"> <label>Content</label> <%= f.text_area :content,class:"form-control" %> </div> <div class="text-center"> <%= f.submit "Save",class:"btn btn-primary" %> </div> <% end %> </div> </div>
.
.
アクション周りの記述です。
def edit @positive = Positive.find(params[:id]) end def update @positive = Positive.find(params[:id]) if @positive.update(positive_params) redirect_to root_path, notice: 'Success!' else flash[:alert] = 'Updated error!' render :edit end end private def positive_params params.require(:positive ).permit( :title, :content) end
.
.
routes.rbです。
Rails.application.routes.draw do root 'positives#index' resources :positives end
$ rails routes Prefix Verb URI Pattern Controller#Action root GET / positives#index positives GET /positives(.:format) positives#index _ POST /positives(.:format) positives#create new_positive GET /positives/new(.:format) positives#new edit_positive GET /positives/:id/edit(.:format) positives#edit positive GET /positives/:id(.:format) positives#show _ PATCH /positives/:id(.:format) positives#update _ PUT /positives/:id(.:format) positives#update
index.html.erb からedit.html.erbのページにいきます。
<% @positives.each do |positive| %> <tr> <td><%= positive.id %></td> <td><%= link_to positive.title %></td> <td> [<%= link_to 'Edit' ,edit_positive_path(positive) %>] [<%= link_to 'Summary'%>] [<%= link_to 'Delete' ,positive_path(positive), method: :delete, data:{confirm:'Are you sure??'} %>]</td> </tr> <% end %>
なぜか、編集画面にいっても元の内容が反映されないです。。。。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/04 12:58