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 trialGregory Sheppard
4,312 PointsJoin Table Woes
Another battle with version differences in the Ruby on Rails courses (or typos, those happen too). I'm currently working on "What is a Join Table?", got about halfway through the video and started hitting errors (or lack of errors in some cases). Currently, around 9:50, when I run the 'should not update the status if nothing has changed' test (and after updating the controller), I'm getting an error for lines of code that don't exist in Jason's controller but do exist natively in mine.
I tried to add code line numbers to lines that were mentioned (on the right side).
Test:
test "should not update the status if nothing has changed" do
sign_in users(:ej)
patch :update, id: @status
assert_redirected_to status_path(assigns(:status))
assert_equal assigns(:status).user_id, users(:ej).id
end
statuses_controller.rb
# PATCH/PUT /statuses/1
# PATCH/PUT /statuses/1.json
def update
@status = current_user.statuses.find(params[:id])
if params[:status] && params[:status].has_key?(:user_id)
params[:status].delete(:user_id)
end
respond_to do |format| 48
if @status.update(status_params) 49
format.html { redirect_to @status, notice: 'Status was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: '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) 77
end
end
Error:
1) Error:
StatusesControllerTest#test_should_not_update_the_status_if_nothing_has_changed:
ActionController::ParameterMissing: param not found: status
app/controllers/statuses_controller.rb:77:in `status_params'
app/controllers/statuses_controller.rb:49:in `block in update'
app/controllers/statuses_controller.rb:48:in `update'
test/controllers/statuses_controller_test.rb:85:in `block in <class:StatusesControllerTest>'
2 Answers
Jason Seifer
Treehouse Guest TeacherIt looks like the status params aren't being set and are required. Try changing this:
def status_params
params.require(:status).permit(:user_id, :content)
end
To this:
def status_params
params.permit(:status).permit(:user_id, :content)
end
Let us know if that helps!
Sean Perryman
13,810 PointsDid you ever get a solution to this problem? I am facing a similar one myself. As Jason Seifer suggested, I changed my params.require
to params.permit
; and ended up with errors on 3 more tests. As it stands I can't get my edit and destroy tests to pass.
Sean Perryman
13,810 PointsFollowing your code, Gregory Sheppard , I changed my set_status back to @status = Status.find(params[:id])
, and took the @status = current_user.statuses.find(params[:id])
and it fixed my other problems. Thanks!
Sean Perryman
13,810 PointsDoh! I am now in the same place you are, getting the same error. Hopefully someone found a solution to this one!