Rumor Has It…

Josh Raiborde
2 min readFeb 22, 2021

--

Flatiron Portfolio Project JavaScript

Coming in from Ruby, Sinatra and Ruby on Rails…into JavaScript, sheesh!

Those were some hurdles to jump over…

The app is called Rumor Has It…

For the frontend, the app has HTML and JavaScript

For the backend it has a Rails API.

AJAX is used to interact with the client and the server

JSON is the communication from that is used

Classes that capture the related data and behavior are present in the .js files

In the backend, there is one “has-many” relationship between post and comment

The app has 3 AJAX calls that Create, Read and Delete

Here’s an example:

// rumor-has-it-frontend/src/comment.js

static submitComment(comment, commentList, postId){

fetch(commentURL, {

method: “POST”,

headers: {

“Content-type”: “application/json”,

“Accept”: “application/json”

},

body: JSON.stringify({

content: comment,

post_id: postId

})

}).then(res => res.json())

.then(comment => {

let newComment = new Comment(comment)

newComment.renderComment(commentList)

})

}

In Rails, RESTful conventions are used

Here’s an example:

# rumor-has-it-backend/app/controllers/posts_controller.rb

def index

render json: Post.all.map {|post| PostSerializer.new(post)}

end

def create

post = Post.new(post_params)

if post.save

render json: PostSerializer.new(post)

end

end

def destroy

post = Post.find(params[:id])

post.destroy

end

seems like the bigger lessons are learned in the lessons leading up to doing the projects.

For some reason, I decided to update ruby from 2.6.1 to 3.0.0

That was a bad idea…

I should’ve stuck with 2.6.1.

One of the reasons is because Flatiron’s curriculum is taught on ruby 2.6.1 and so there was no point in updating to ruby 3.0.0

One of the other reasons was, the command “learn” wasn’t being recognized.

I couldn’t run “rails new xxx –api”

I kept getting an error

“Gem::Ext::BuildError: ERROR: Failed to build gem native extension”

I was stuck for a couple of days, getting help from the coaches and my instructor

Finally, on the third day, we had a breakthrough.

in the terminal run: xcode-select — install

After that’s finished, quit your terminal, not just the window, open it back up, and then try the rails api command again.

Here comes another but…

But even after fixing the that issue, I kept having to set the default ruby back to 2.6.1 for every lab I opened.

I was typing in “rvm use default 2.6.1”

It would set my ruby to 2.6.1 but when I opened up another lab, it went back to ruby 3.0.0

After googling and googling and googling… … …

I finally found something that worked

“rvm — default use 2.6.1”

This set my ruby to 2.6.1

Whew!

Lesson learned, if it ain’t broke, there’s prob not a reason to update

--

--

Josh Raiborde
Josh Raiborde

Written by Josh Raiborde

Hello, I am a young enthusiastic Software Engineer. Looking forward to an opportunity to use my skills for mutual benefits and growth as well.

No responses yet