railsでwebページを作っています。
自身の投稿を編集できるようにしたいのですが、以下の問題が発生しています。
プログラミング初心者なので、基本的な質問・間違いかもしれません。
お手数おかけしますが、教えて頂けると大変助かります。よろしくお願いいたします。
<発生している問題>
・編集ボタンが押せるときと押せないときがある
・押せるときは、railsを起動して最初の動作のとき(いつもではない)
・押せないときは、ボタンのクリックはできるが、ページの遷移・編集内容の反映は行われない
<試したこと>
・問題が発生しているeditコントローラーと似た名前のコントローラー(indexedit)があったので、名前を変更しました
<環境・ツール>
Windows10
Ruby 2.6.6
Ruby on Rails
V S code
XAMPP Control Panel v3.2.4 (Apache MySQL)
Node.js
Yarn
<コード>
・編集ページのビュー
<div class="mies-container"> <%= form_for @my do |f| %> <div class="field"> <%= f.label :image %> <%= f.file_field :image %> </div><br> <div class="field"> <%= f.label :images %> <%= f.file_field :images %> </div><br> <div class="field"> <%= f.label :images1 %> <%= f.file_field :images1 %> </div><br><br><br> <div class="field"> <%= f.label :tittle %> <%= f.text_field :tittle, size: 50 %> <%= %> </div><br> <div class="field"> <%= f.label :highlight %> <%= f.text_area :highlight, size: 200 %> </div> <br><br><br> <div class="field"> <%= f.label :date %> <%= f.date_field :date, size: 50 %> </div><br> <div class="field"> <%= f.label :size %> <%= f.text_field :size, size: 50 %> </div> <%= f.submit "編集する" %> <% end %>
・ルート
get 'mies/top' => 'mies#top' get 'mies/index' => 'mies#index' get 'mies/new' => 'mies#new' post 'mies/new' => 'mies#create' get 'mies/ichiran' => 'mies#ichiran' get 'mies/:id' => 'mies#show' ,as:'my' get 'mies/:id/edit' => 'mies#edit', as:'edit_my' patch 'mies/:id' => 'mies#update' delete 'mies/:id' => 'mies#destroy'
・コントローラー
def top @mies = My.last(6) end def index @mies = My.all end def show @my = My.find(params[:id]) end def new @my = My.new end def create my = My.new(my_params) if my.save redirect_to :action => "index" else redirect_to :action => "new" end end def ichiran @mies = My.all end def edit @my = My.find(params[:id]) end def update my = My.find(params[:id]) if my.update(my_params) redirect_to :action => "ichiran" else redirect_to :action => "new" end end def destroy my = My.find(params[:id]) my.destroy redirect_to action: :indexedit end private def my_params params.require(:my).permit(:image, :images, :images1, :tittle, :highlight, :date, :size) end
・ルート一覧
Prefix
1 letters_new GET /letters/new(.:format) letters#new 2 POST /letters/new(.:format) letters#create 3 letters_index GET /letters/index(.:format) letters#index 4 mies_top GET /mies/top(.:format) mies#top 5 mies_index GET /mies/index(.:format) mies#index 6 mies_new GET /mies/new(.:format) mies#new 7 POST /mies/new(.:format) mies#create 8 mies_ichiran GET /mies/ichiran(.:format) mies#ichiran 9 my GET /mies/:id(.:format) mies#show 10 edit_my GET /mies/:id/edit(.:format) mies#edit 11 PATCH /mies/:id(.:format) mies#update 12 DELETE /mies/:id(.:format) mies#destroy 13 rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create 14 rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create 15 rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create 16 rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check 17 rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create 18 rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create 19 rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index 20 POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create 21 new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new 22 edit_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) rails/conductor/action_mailbox/inbound_emails#edit 23 rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show 24 PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update 25 PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update 26 DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#destroy 27rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create 28 rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show 29 rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show 30 rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show 31 update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update 32 rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create 33
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/19 23:39
2021/01/19 23:49
2021/01/20 05:18