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
Todd Nestor
10,689 PointsMade it through the tutorial then I noticed somewhere along the way I broke it: NoMethodError in Statuses#show
I made it clear through the tutorial, even deployed it to: http://shrouded-mesa-2199.herokuapp.com/
then I realized that when I post a new status, while the status posts, it takes me to the show status page where it is broken! This is true for any of the links to an individual status, also I can't delete statuses.
My github repository is here: https://github.com/toddnestor/hercbook
My show status page looks like this:
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @status.user.full_name %>
</p>
<p>
<strong>Content:</strong>
<%= @status.content %>
</p>
<%= link_to 'Edit', edit_status_path(@status) %> |
<%= link_to 'Back', statuses_path %>
What other pages do you need to see to help me?
I am running Rails 4.1 and Ruby 2.1.1, I have been able to fix all the other errors that came from the version discrepancies as we have gone along (except some of the tests that require sign_on, those I am still working on), and I don't think this error has to do with the version discrepancy.
What is going on that I can't find?
1 Answer
Todd Nestor
10,689 PointsI found the problem by going back and checking out my old commits from git until I checked one out that ran properly. The problem was in my app / controllers / statuses_controller.rb file,
I had written it like this:
class StatusesController < ApplicationController
before_action :authenticate_user!, only: [:new, :destroy, :edit, :show, :update]
# GET /statuses
# GET /statuses.json
def index
@statuses = Status.all.reverse
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 }
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(:user_id, :content)
end
end
So for now I reverted it to the old version that looked the one below and it is now working. I believe I had made some changes attempting to get the tests to work since I am running Rails 4.1 and ruby 2.1.1. I will work more on getting the tests to run later.
You can see it works now at: http://shrouded-mesa-2199.herokuapp.com/statuses and you're welcome to join it, still waiting for my billion dollars to roll in from it also :)
class StatusesController < ApplicationController
before_action :set_status, only: [:show, :edit, :update, :destroy]
# GET /statuses
# GET /statuses.json
def index
@statuses = Status.all.reverse
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 }
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(:user_id, :content)
end
end