https://www.sejuku.net/blog/65175のサイトをもとに、画像アップロード機能を実装していたらエラーが出てしまいました。
ActionView::Template::Error (Can't resolve image into URL: undefined method `to_model' for #<AvatarUploader:0x000000000bf84de0> Did you mean? to_xml): 11: </p> 12: 13: <p> 14: <%= image_tag @yuuzi.avatar_path %> 15: </p> 16: 17: <%= link_to 'Edit', edit_yuuzi_path(@yuuzi) %> | app/views/yuuzis/show.html.erb:14:in `_app_views_yuuzis_show_html_erb__557274456_96452760'
controller
1class YuuzisController < ApplicationController 2 before_action :set_yuuzi, only: [:show, :edit, :update, :destroy] 3 4 # GET /yuuzis 5 # GET /yuuzis.json 6 def index 7 @yuuzis = Yuuzi.all 8 end 9 10 # GET /yuuzis/1 11 # GET /yuuzis/1.json 12 def show 13 end 14 15 # GET /yuuzis/new 16 def new 17 @yuuzi = Yuuzi.new 18 end 19 20 # GET /yuuzis/1/edit 21 def edit 22 end 23 24 # POST /yuuzis 25 # POST /yuuzis.json 26 def create 27 @yuuzi = Yuuzi.new(yuuzi_params) 28 29 respond_to do |format| 30 if @yuuzi.save 31 format.html { redirect_to @yuuzi, notice: 'Yuuzi was successfully created.' } 32 format.json { render :show, status: :created, location: @yuuzi } 33 else 34 format.html { render :new } 35 format.json { render json: @yuuzi.errors, status: :unprocessable_entity } 36 end 37 end 38 end 39 40 # PATCH/PUT /yuuzis/1 41 # PATCH/PUT /yuuzis/1.json 42 def update 43 respond_to do |format| 44 if @yuuzi.update(yuuzi_params) 45 format.html { redirect_to @yuuzi, notice: 'Yuuzi was successfully updated.' } 46 format.json { render :show, status: :ok, location: @yuuzi } 47 else 48 format.html { render :edit } 49 format.json { render json: @yuuzi.errors, status: :unprocessable_entity } 50 end 51 end 52 end 53 54 # DELETE /yuuzis/1 55 # DELETE /yuuzis/1.json 56 def destroy 57 @yuuzi.destroy 58 respond_to do |format| 59 format.html { redirect_to yuuzis_url, notice: 'Yuuzi was successfully destroyed.' } 60 format.json { head :no_content } 61 end 62 end 63 64 private 65 # Use callbacks to share common setup or constraints between actions. 66 def set_yuuzi 67 @yuuzi = Yuuzi.find(params[:id]) 68 end 69 70 # Never trust parameters from the scary internet, only allow the white list through. 71 def yuuzi_params 72 params.require(:yuuzi).permit(:name, :avatar_path) 73 end 74end 75
show
1<p id="notice"><%= notice %></p> 2 3<p> 4 <strong>Name:</strong> 5 <%= @yuuzi.name %> 6</p> 7 8<p> 9 <strong>Avatar path:</strong> 10 <%= @yuuzi.avatar_path %> 11</p> 12 13<p> 14<%= image_tag @yuuzi.avatar_path %> 15</p> 16 17<%= link_to 'Edit', edit_yuuzi_path(@yuuzi) %> | 18<%= link_to 'Back', yuuzis_path %>
初心者なので優しく答えていただけると嬉しいです。お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/21 11:18
2019/10/21 12:05
2019/10/21 12:41
2019/10/21 13:00
2019/10/22 00:10