現在Railsでメモ帳のようなものを作っています
そこで投稿と閲覧はできるのですが削除の方法がわかりません
調べてみたのですがエラーが出てしまいうまくいきません
'/tweet/index(tweet.id)'
の部分が悪いのだと思うのですがどう直したらうまくいきますか?
root.rb
Rails.application.routes.draw do get 'tweets/index' get 'tweets/new' post "tweets" => "tweets#create" get 'tweets/show' end
tweets_controller.rb
controller
1class TweetsController < ApplicationController 2 def index 3 @tweets = Tweet.all 4 end 5 6 def new 7 end 8 9 def show 10 end 11 12 def create 13 @tweet = Tweet.new 14 @tweet.day = params[:tweet][:day] 15 @tweet.title = params[:tweet][:title] 16 @tweet.about = params[:tweet][:about] 17 @tweet.save 18 redirect_to '/tweets/index' 19 end 20 21 def destroy 22 @tweet = Tweet.find(params[:id]) 23 @tweet.destroy 24 redirect_to '/tweet/index' 25 end 26end
index.html.erb
<div class="container"> <% @tweets.each do |tweet| %> <h2><%= tweet.day %></h2> <h1><%= tweet.title %></h1> <p><%= tweet.about %></p> <%= link_to "[Delete]", '/tweet/index(tweet.id)', method: :delete, data: { confirm: "are you sure?" } %> <hr> <% end %> <%= link_to "投稿する", '/tweets/new', class: "btn btn-primary" %> </div>
new.rb
<div class="container"> <div class="form-horizontal"> <%= form_for Tweet.new do |f| %> <%= f.label :day, "日付を入力" %><br> <%= f.text_field :day, :class => "form-control" %><br> <%= f.label :title, "タイトルを入力" %><br> <%= f.text_field :title, :class => "form-control" %><br> <%= f.label :about, "内容を入力" %><br> <%= f.text_area :about, :class => "form-control" %><br> <%= f.submit "投稿", :class => "btn btn-primary" %> <% end %> </div> </div>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。