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

Chase Lee
Chase Lee
29,275 Points

Create Treebook Using Rails 4.

Hi everyone I wanted to do a project like Treebook just for fun. But I don't know if following along using Rails 4 and Ruby 2.1.0 would mess things up... I definitely don't want to use on older version of ruby or rails. But I don't think I'm quite at that level where I can do it on my own. Any suggestions?

Thanks for everything!

Chase

Nick Fuller
Nick Fuller
9,027 Points

I think you should stick your neck out there and go for! If you run into trouble... you can always use the forums to post for help and send it off to the google gods if need be!

You can do it, don't let rails intimidate you. It's your friend not your enemy!

5 Answers

Chase Lee
Chase Lee
29,275 Points

Thanks everyone! I think I'll dive in and start learning! Yay! :smile:

Glenn Harris
Glenn Harris
7,101 Points

Only two things need to be changed IMO.

1)When they start talking about "attr:accessible", ignore that. Instead of the updating the status.rb model you're going to need to update the status controller.

Example of the create method in your statuses controller:

def create
@status = current_user.statuses.new(status_params)
...
end

... ...

private
def status_params
params.require(:status).permit(:name, :content, :user_id)
end

2)Twitter bootstrap. The CSS he references is from the old version. The names of the classes have been changed. Here is a link: http://getbootstrap.com/css/#grid .

I'm happy to help if you want more detail on anything...

NameError in StatusesController#create

undefined local variable or method `private' for #<StatusesController:0x4886760>

Extracted source (around line #38): end

  private
  def status_params
  params.require(:status).permit(:name, :content, :user_id)
  end

I was trying to put that piece of code since your right, thats the only thing thats not allowing me to continue, Can you be more specific where that should be placed since i am still not able to input user_id through the forms.

# 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 action: 'show', status: :created, location: @status }
  else
    format.html { render action: '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 { head :no_content } else format.html { render action: 'edit' } format.json { render json: @status.errors, status: :unprocessable_entity } end end end

I am guessing it thas to be around there since that were is you code is pointing at.

Nevermind found it, it already exists but at the end of the controller!!!

For anybody else having trouble in stage 4, you also need to add devise to be able to pass information through the forms, so when you create a new user incognito, it allows you to pass the arguemnts. The code you put in your application_controller.rb and is the following

before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << [:username, :first_name, :last_name, :profile_name] end

That is on devise documentation on strong parameteres the lazy way to do it. Since we are barely learning rails thats the best way to do it in my opinion :), and quickest so you can keep studying! Keep railing away :D

https://github.com/plataformatec/devise#strong-parameters

karim manji
karim manji
1,966 Points

Greetings James,

I just started on the Treebook app a few days ago. If you follow the video instructions to a T (like I did) you'll end up installing the newest RoR, however, unless you have a strong coding background, you're going to run into issues each step along the way. i finally ditched the latest versions and just cloned/downloaded their skeletal app to continue on (older versions of ruby and rails). In my opinion, it's not worth all the hassle of figuring out why you're not getting the results from the video. I'm trying to learn the fundamentals of coding, not the differences b/w version numbers. If I were to start again, I would've just cloned their skeletal app from the beginning.

Wish someone had warned me...

Good luck,

Karim.

Chase Lee
Chase Lee
29,275 Points

Thanks Karim.

Learning the hassles actually makes you understand how rails works, the MVC model and it allows you to expand your mind on all the different files rails has.

Learning about documentation is also helpful