ruby on rails - Why won't my edit and delete links work on my index page? -


i have list of post titles sorted under alphabetical letter edit links , delete links aren't working on index page. work when add them show page. thought had working before error "undefined local variable posts" have tried this.

edit_post_path(posts) edit_post_path(@post) edit_post_path(@posts) 

posts controller

def index       @posts = current_user.posts.all.group_by {|post| ('a'..'z').include?(post.title.downcase[0]) ? post.title.downcase[0] : '#' } end  def edit     @post = current_user.posts.find(params[:id]) end   def update     @post = current_user.posts.find(params[:id])      if @post.update_attributes(post_params)       redirect_to action: "index"       flash[:success] = "post updated"     else       render 'edit'     end  end   def destroy     @post = current_user.posts.find(params[:id])     @post.destroy     redirect_to action: "index"     flash[:success] = "post deleted" end 

index.html.erb

<% @posts.keys.sort.each |key| %>      <div class= "posts-letter"><%= key.upcase %></div>    <% @posts[key].each |t| %>         <div class="post">              <div class="post-title"><%= t.title %></div>            <div class="action-buttons">                 <%= link_to edit_post_path(post), class: "edit-button" %>                   <i class="fa fa-pencil"></i>               <% end %>                <%= link_to  post, method: :delete, data: { confirm: "you sure?" }, class: "delete-button" %>                   <i class="fa fa-trash"></i>               <% end %>            </div>        </div>   <% end %>  <% end %> 

it appears t post object inside each. pass edit_post_path. or name post instead of t.

  <% @posts[key].each |post| %>         <div class="post">              <div class="post-title"><%= post.title %></div>            <div class="action-buttons">                 <%= link_to edit_post_path(post), class: "edit-button" %>                   <i class="fa fa-pencil"></i>               <% end %>                <%= link_to post, method: :delete, data: { confirm: "you sure?" }, class: "delete-button" %>                   <i class="fa fa-trash"></i>               <% end %>            </div>        </div>   <% end %> 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -