前提・実現したいこと
- 初めての投稿です。よろしくお願いいたします。
- Rails/Hamlにてプロフィール作成サイトを作っています。
- edit.html.hamlでのsyntax errorが解消できずにいます。
prefixで直接アクセス「/aboutmes/:id/edit」「edit_aboutme_path」した時にエラー
※ビュー上の「編集」ボタン押下時も同様のエラー
発生している問題・エラーメッセージ
SyntaxError in AboutmesController#edit /Users/ryootani/projects/travel-log/app/views/aboutmes/edit.html.haml:38: syntax error, unexpected keyword_ensure, expecting end-of-input ensure ^~~~~~ Extracted source (around line #38): = fo.submit "新About決定ボタン", class: "newSendBtnZ" ### 上記submitの行は36行目にあたり、エラー文で指摘している38行目は記述なしです。
該当のソースコード
haml
1# app/views/aboutmes/edit.html.haml 2 3.header 4 .header__title 5 = link_to "About Me", aboutmes_path, class: "header__title--text" 6 .header__right 7 = link_to "ノックノック画面に戻る", root_path, class: "header__right--btn" 8 = link_to "新規プロフィール作成はこちら", new_aboutme_path, class: "header__right--btn" 9.contents 10 11 .profileTitle 12 プロフィールの編集 13 14 .profileDatas 15 .profileData 16 = form_for @about do |fo| 17 .newText 18 = fo.label :name, "プロフィールを書こう" 19 %br 20 = fo.text_area :content, class: "newTextZ", placeholder: "国籍/ルート/期間/一言!" 21 .newImage 22 = fo.label :name, "写真アイコンを貼ろう" 23 %br 24 %i.fab.fa-tripadvisor 25 = fo.file_field :image, class: "newImageZ" 26 .newUrl 27 = fo.label :name, "SNSのURLを貼ろう" 28 %br 29 = fo.url_field :url, class: "newUrlZ" 30 .newSendBtn 31 = fo.submit "新About決定ボタン", class: "newSendBtnZ" 32
haml
1# app/models/about.rb 2 3class Aboutme < ApplicationRecord 4 mount_uploader :image, ImageUploader 5 validates :content, :image, :url, presence: true 6end
rails
1#app/controller.rb 2 3class AboutmesController < ApplicationController 4 5 def index 6 @abouts = Aboutme.all 7 end 8 9 def new 10 @about = Aboutme.new 11 end 12 13 14 def create 15 @about = Aboutme.new(about_params) 16 if @about.save 17 redirect_to aboutmes_path, notice: "新規About作成成功!" 18 else 19 redirect_to new_aboutme_path, notice: "再作成してください" 20 end 21 end 22 23 def show 24 @about = Aboutme.find(params[:id]) 25 end 26 27 def edit 28 @about = Aboutme.find(params[:id]) 29 end 30 31 def update 32 about = Aboutme.find(params[:id]) 33 about.update(about_params) 34 redirect_to aboutme_path(about.id) 35 end 36 37 def destroy 38 about = Aboutme.find(params[:id]) 39 about.destroy 40 redirect_to aboutmes_path 41 end 42 43 private 44 def about_params 45 params.require(:aboutme).permit(:content, :image, :url) 46 end 47end
確認したこと
- = link_to "新About決定ボタン", new_aboutme_path, class: "newSendBtnZ" do
での書き換え(hamlのためendは不要の認識なので、do不足によるものか確認) ->別のエラーが発生
2. submitとform_forの構文確認 ->(変数foにしている)問題なさそうです
3. new.html.hamlの記述(form_forで振り分け先判別) ->同内容です
3. ルーティングを7つのアクション許可「resources :aboutmes」 ->状況変わらず
補足情報(FW/ツールのバージョンなど)
Rails 5.0.7.2
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー