Home>

I'm making a Twitter clone with Rails.
When I coded and logged in, the following error was displayed.
I would appreciate it if you could tell me if the micropost_id has been modified or if something else is wrong.

]

views/favorites/_micropost_button.html.erb

<% if current_user.likes? (Micropost)%>
<% = form_with (model: current_user.favorites.find_by (micropost_id, micropost.id), local: true, method:: delete, class: "d-inline") do | f |%>
  <% = hidden_field_tag: micropost_id, micropost.id%>
  <% = f.submit'Unfavorite', class:'btn btn-danger btn-sm'%>
<% end%>
<% else%>
<% = form_with (model: current_user.favorites.build, local: true, class: "d-inline") do | f |%>
  <% = hidden_field_tag: micropost_id, micropost.id%>
  <% = f.submit'Favorite', class:'btn btn-primary btn-sm'%>
<% end%>
<% end%>

views/microposte/_microposts.html.erb

<ul>
<% microposts.each do | micropost |%>
  <li>
      " alt = "">
      
        
        <% = link_to micropost.user.name, user_path (micropost.user)%><span>posted at<% = micropost.created_at%></span>
        
        
        <p><% = micropost.content%></p>
        
        
        <% if current_user == micropost.user%>
          <% = link_to "Delete", micropost, method:: delete, data: {confirm: "You sure?"}, Class: "btn btn-danger btn-sm"%>
        <% end%>
        <% = render'favorites/micropost_button', micropost: micropost%>
        
      
  </li>
<% end%>
<% = paginate microposts%>
</ul>


views/toppages/index.html.erb

<% if logged_in?%>
  
    
    <% = form_with (model: @micropost, local: true) do | f |%>
        
        <% = f.text_area: content, class: "form-control", rows: 5%>
        
      <% = f.submit "Post", class: "btn btn-primary btn-block"%>
    <% end%>
  </aside>
    
    <% = render "microposts/microposts", microposts: @microposts%>
    
  
<% else%>
  
    
       Welcome to the Microposts 
    <% = link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary"%>
    
  
<% end%>
  • Answer # 1

    <% = form_with (model: current_user.favorites.find_by (micropost_id, micropost.id),
    It was micropost_id: instead of micropost_id ,.