Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Help with Ruby

Hell all. I am having an issue while trying to follow along with the tutorial on building the Treebook project. For some reason the link_to "Delete" method is not working. instead of deleting the status, it shows the page for the status. Can anyone help with this? Below is the code from my index.html.erb file. I have ruby version 1.9.3-p545 (i386-mingw32) installed and using rails version 4.1.1


<div class="page-header"> <h1>All of the Statuses</h1> </div>

<% @statuses.each do |status| %> <div class="status"> <strong><%= status.name %></strong> <p><%= status.content %></p> <div class="meta"> <%= link_to "Show", status %> | <span class="admin"> <%= link_to "Edit", edit_status_path(status) %> | <%= link_to "Destroy", status, method: :delete, data: { confirm: "are you sure you want to delete this status?" } %> </span> </div> </div> <% end %>

<%= link_to 'New Status', new_status_path %>

Could you post your StatusController code as well please?

Hello Ethan,

Below is the StatusController code.

class StatusesController < ApplicationController before_action :set_status, only: [:show, :edit, :update, :destroy]

# GET /statuses # GET /statuses.json def index @statuses = Status.all end

# GET /statuses/1 # GET /statuses/1.json def show end

# GET /statuses/new def new @status = Status.new end

# GET /statuses/1/edit def edit end

# POST /statuses # POST /statuses.json def create @status = Status.new(status_params)

respond_to do |format|
  if @status.save
    format.html { redirect_to @status, notice: 'Status was successfully created.' }
    format.json { render :show, status: :created, location: @status }
  else
    format.html { render :new }
    format.json { render json: @status.errors, status: :unprocessable_entity }
  end
end

end

# PATCH/PUT /statuses/1 # PATCH/PUT /statuses/1.json def update respond_to do |format| if @status.update(status_params) format.html { redirect_to @status, notice: 'Status was successfully updated.' } format.json { render :show, status: :ok, location: @status } else format.html { render :edit } format.json { render json: @status.errors, status: :unprocessable_entity } end end end

# DELETE /statuses/1 # DELETE /statuses/1.json def destroy @status.destroy respond_to do |format| format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' } format.json { head :no_content } end end

private # Use callbacks to share common setup or constraints between actions. def set_status @status = Status.find(params[:id]) end

# Never trust parameters from the scary internet, only allow the white list through.
def status_params
  params.require(:status).permit(:name, :content)
end

end