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 Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

Kris Chery
Kris Chery
935 Points

Having problems calling <%= @status.user.first_name %> to my views on rails 4.2.4.

Now I made sure that the application controller accepted the user inputs and it shows so in the console. I made sure that they status params accepted the user _id. This also shows in the console when i run Status.first, There is a user_id field but for some reason when I call method like .first_name, .last_name. Can't seem to pin point it.

here is the code i think is relevant to show. let me know if you need anything else that may help me decipher it.

Application Controller

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_action :configure_permitted_params, if: :devise_controller?


  protected

    def configure_permitted_params
      devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:first_name, :last_name,
                                                :profile_name, :email, :password, :remember_me,
                                                 :password_confirmation)}
    end
end


Status Controller

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(:content, :user_id)
    end
end

Status Controller

class Status < ActiveRecord::Base
  belongs_to :user
end


Show.hmtl.erb


<p>
  <strong>Name:<%= @status.user.first_name %></strong>

</p>

<p>
  <strong>Content:</strong>
  <%= @status.content %>
</p>

<%= link_to 'Edit', edit_status_path(@status) %> |
<%= link_to 'Back', statuses_path %>

7 Answers

In routes.rb:

get 'feed', to: "statutes#index", as: :feed

Do we mean statuses? Not statutes.

Yeah - that works much nicer!

Testing, people! Write some tests!! ;-)

To explain ...

You get the error: uninitialized constant StatutesController which means something is looking for a controller called Statutes. That's a clear typo - and you app works nicely now with that corrected.

You have some styling issues, though.

Kris Chery
Kris Chery
935 Points

YES!!!! This is a prototype for a much bigger that I am planning on doing. I just wanted to absorb the material

:+1:

Kris Chery
Kris Chery
935 Points

How to I get to can i set up the profile route. I don't know why but same problem is occurring. I build the profile controller the way I was instructed.

Cool - the material is good. But I do recommend taking a TDD approach in the real world; it will save you HOURS at a time. Get familiar with the testing tools and write tests first. Treehouse's testing library is crap; I hope they build on it soon. Try this book - it is DULL but gets the point across.

If I can help at all on a commercial level, do let me know. I'm happy to get involved if only from a project direction perspective, or whatever you need.

Steve.

Kris Chery
Kris Chery
935 Points

I think the link to github would be more useful

https://github.com/krischery2150/treebookAPP

Yeah - cool. Can you describe the problem you're having? I'm not sure what I'm looking for.

Thanks,

Steve.

Kris Chery
Kris Chery
935 Points

Hey Steve taking you up on your offer,

I can't seem to get the profile page to work. I checked the controller, the model but can't seem to pinpoint the problem. Also once the user logs in if i try going on the all statuses page, it also brings up the same page.

here is my github address: https://github.com/krischery2150/treebookAPP

Any help would be much appreciated.

What are you expecting the code to do and what does it do instead?

Kris Chery
Kris Chery
935 Points

I think I figured it out. I just add to empty out the database from my previous statuses. rake db:reset solved my problem. Thanks for reaching to help

No problem. Glad you got it sorted! :+1: :smile:

Happy to help if you run into Rails issues!

Kris Chery
Kris Chery
935 Points

I am expecting content of the show profile page to display the full name and the capsule that they only have created. I checked the controller and it seems to tie @user with the id and which means that it should have came back correct . When i copy and paste the profile_name after the root url. The page return uninitialized constant. Steve Hunter

OK - I've downloaded that and will see if I can track the error.

Are you testing this before you develop your features? I can't recommend utilising Capybara and RSpec highly enough. They really help make sure your app works as intended; testing drives the design and development process. Good unit and integration testing is key to good application production.

Kris Chery
Kris Chery
935 Points

I didn't because since i have been working on rails 4.2.4, I can't seem to follow the tutorial as well so i skipped to the routing and added the content that didn't involve testing. I still watched the videos

Yeah, I'll add that to the millions of excuses I've heard for 'why I didn't test'. :wink:

I've got the localhost running; nice styling! Bootstrap? Yes.

I've signed up (some dodgy spacing on that form) and have tried to click the 'All Statuses' button - that throws an error with StatusController. Is that what we're trying to fix? That's caused by a badly named variable, StatutesController.

Kris Chery
Kris Chery
935 Points

Steve you could absolutely a good person to talk to. I am in the building phase of my app and i want to make sure i know the things that i don't know before i deploy it. I just finished the entire prototype and trademarked the platform, now they are waiting on my code to copyright it. I have been learning intensively for the past year but can't seem to get a clear process down to execute this. Everything is planned out and now i am questioning my programming abilities. I did many projects before this but i blank out when i start this project for some reason. Talking to someone that knows and can give me direction would be much appreciated. Let me know if you want to chat sometime

Happy to chat anytime. I've got a few projects of my own on the go at the moment and they do take up plenty of my time, but I get paid a daily rate, so that's good!! I love being self-employed for that reason.

We should probably take this off the Treehouse pages as it is a commercial conversation ... email is on my holding page. Or there's Twitter or Skype.

Steve.

Kris Chery
Kris Chery
935 Points

Haha, I have been offered jobs but i stayed committed to this app for the past year, so what you describe definitely sounds like the life. I can't seem to access that page though . Do you have an email. i can send you a quick one.

I edited the link ... it now gets to my holding page. Apologies!