Home>

I'm learning ruby ​​on rails with progate and using CarrierWave as an application
I'd like to implement an image posting function, but I get an error and can't execute it.

Corresponding source code
# app/views/posts/new.html.erb

  
     Post 
  <% = form_tag ("/ posts/create", {multipart: true}) do%>
     
      <textarea name = "content"></textarea><br>
      <% = f.label: image%>
      <% = f.file_field: image%>
     
  <% end%>
# app \ controllers \ posts_controller.rb
class PostsController</pre>
<pre><code># app \ views \ posts \ index.html.erb
  
  <% @ posts.each do | post |%>
      
        
    ">
        
        
          
          
          <% = link_to (post.content, "/posts/#{post.id}")%>
            " width = "100">
        
      
  <% end%>
  
What I tried Supplementary information (FW/tool version, etc.)

Rails 5.2.4.2
ruby 2.6.6p146

  • Answer # 1

    The error content is "There is no method or variable called f"
    thisfIs generallyform_forIt is used in.

    form_for @post, html: {multipart: true} do | f |
      f.file_field: image
    end

    Also, the use of form_tag and form_for seems to be deprecated.
    https://qiita.com/hmmrjn/items/24f3b8eade206ace17e2

  • Answer # 2

    Is it possible to replace it with file_field_tag?

Related articles