Robert Paul

Joined

620 Experience
3 Lessons Completed
0 Questions Solved

Activity

Posted in Group Chat with ActionCable: Part 4 Discussion

Hey Chris, Can you elaborate on the difference between what you use chatrooms_channel.rb and chatrooms.coffee for?

My interpretation so far: Chatroom_channel.rb is saying "These are the things we want to listen to" and chatrooms.coffee is where we say "Ok, those things we're listening to, if some new things happen, do these actions".

Hey Chris. It'd just be one book at a time.

Edit: No, there would not be an inventory system. A book create action would only create one new book in the database.

Hey GoRails devs,

I am in the middle of setting up a marketplace (with stripe) and could use some help in conceptually thinking about the model associations. In the marketplace: a user can sell or buy a book, and there is no cart system. If a user wants to buy a book they just click "purchase book" on a book show page.

Here's one way I thought of:

For the Book model, attributes of:

    sold_by :integer (user id of seller)
    bought_by :integer (user id of person buying)
    name :string
    author :string
    etc....

or, another way is setting up a model just to handle the seller/buyer purchase relationship, but I'm not sure how that would look. Thoughts? This is a new challenge for me.

Posted in Group Chat with ActionCable: Part 4 Discussion

Definitely, I don't know why either. The only thing I could think of is at one time my app was Rails 4, and then also Rails 5 beta. Perhaps that requirement never got fully uninstalled or something. Beats me. Oh well, works now though!

Posted in Group Chat with ActionCable: Part 4 Discussion

Just offering a solution here for some error messages I kept getting. The server error I got was:


Started GET "/cable" for ::1 at 2017-02-09 16:35:06 -0800

ActionController::RoutingError (No route matches [GET] "/cable"):

I added to my routes.rb :


Rails.application.routes.draw do
mount ActionCable.server, at: '/cable'
...
...
end

Not sure why in this repo example action cable works without it, but in my app once I added this everything worked. I'm using Rails '5.0.1' for reference.

Hi Naveen, are you still seeing the double render? If so, can you past your UsersController and your HomesController code here? Maybe it's in there.

Posted in Rails Application Structure | GoRails

Hey Chris, at 5:10 you mention setting a username and password for your database. Can you expand on that? I looked at my own heroku account and I just see a postgres url for my config variables. Do I just set a username and password for it like setting env variables for AWS S3 with the figaro gem? Also, is it not secure otherwise? Thanks! Tried looking up more on this on http://guides.rubyonrails.o... but didn't find anything.

The only thing that comes to mind is either you have extra <% yield %> tags in your application.html.erb, or you are calling the same thing twice in your controllers. See if you have some code you forgot to take out. Your hint might be that your footer partial, and other footer file are not rendering twice. See why that's rendering correctly. Let me know if you figure it out! :)

Posted in Group Chat with ActionCable: Part 4 Discussion

I created a new ruby symbol "e.g. :actioncable_user_id" specifically for this action cable use.

In connection.rb


module ApplicationCable
class Connection < ActionCable::Connection::Base

identified_by :current_user

def connect
self.current_user = find_verified_user
logger.add_tags "ActionCable", "User #{current_user.id}"
end

protected

def find_verified_user
current_user = User.find_by(id: cookies.signed[:actioncable_user_id])

current_user || reject_unauthorized_connection
end

end
end

and in my sessions_helper.rb (used for logging in / logging out)


module SessionsHelper

# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
#below is unique code added for ActionCable find_verified_user
cookies.signed[:actioncable_user_id] = user.id
end
end

Ok, my tabbing does not look like that. Don't judge me! lol

Late to the conversation. I had the same issue originally. I just created a new symbol unique for actioncable.

connection.rb looks like

module ApplicationCable
        class Connection < ActionCable::Connection::Base

                identified_by :current_user

                def connect
                        self.current_user = find_verified_user
                        logger.add_tags "ActionCable", "User #{current_user.id}"
                end

                protected

                def find_verified_user
                        current_user = User.find_by(id: cookies.signed[:actioncable_user_id])

                        current_user || reject_unauthorized_connection
                end

        end
end

and in my sessions_helper.rb

module SessionsHelper

        # Logs in the given user.
        def log_in(user)
            session[:user_id] = user.id
         #below is unique code added for ActionCable find_verified_user
            cookies.signed[:actioncable_user_id] = user.id
        end
end

Posted in Group Chat with ActionCable: Part 4 Discussion

Don't worry about this. Worked on it today. Figured it out!

Posted in Group Chat with ActionCable: Part 4 Discussion

Ok cool. If current user already checks that, do you have any suggestions for how to rewrite that? Would it just be:


def connect
self.current_user = current_user
logger.add_tags "ActionCable", "User #{current_user.id}"
end

Posted in Group Chat with ActionCable: Part 4 Discussion

Hi Chris,

At 5:59, in the connection.rb file you add:

protected

def find_verified_user
if current_user = env['warden'].user
current_user
else
reject_unauthorized_connection
end
end

If I'm not using devise, is "env['warden'].user" just the devise way of authenticate_user ? Is this just to make sure the current_user is the logged_in user? Want to make sure I'm implementing correctly.

Thanks!

Posted in Group Chat with ActionCable: Part 3 Discussion

Much appreciated!

Posted in Group Chat with ActionCable: Part 3 Discussion

Note to self. Tabs matter. Thanks! Is it a js thing or coffee thing?

Posted in Group Chat with ActionCable: Part 3 Discussion

Cool! Another question on this. I'm just doing the console log part and I'm getting error:

Uncaught ReferenceError: e is not defined

Do you know why that'd be? I have this in my coffee file.

$(document).on "turbolinks:load", ->
$("#new_message").on "keypress", (e) ->
console.log e.keyCode

Posted in Group Chat with ActionCable: Part 3 Discussion

Hi Chris,

At 10:54 you write in the .coffee file $(#new_message), but in how I'm implementing this my form looks like <%= form_for :message, url: group_chat_path %> so I don't think the js can grab an id of #new_message. Do you have any suggestions for how I should update this piece of coffee code? Otherwise I'll just to try rewrite my forms successfully.

Shakycode, thanks for the response!

I'm definitely going to concentrate on getting better at ruby. Ruby warrior looks awesome! Right up my alley. I've written down the resources you mentioned, I'll start with ruby warrior and reading a ruby book.

I guess it's a good thing that struggling should be considered the norm. It at least validates that the challenges I've faced so far are just part of the role of being a developer, I'm still doing it right.

Sometimes it helps to take a step back

Absolutely. There's something about a good nap or a night of sleep to just let your brain process it, and get some fresh perspective on it the next day. Been there for sure. I'll definitely reach out! Beginners could always use a buddy :)

Jacob, thanks for replying!

Yes yes, I totally agree. Time spent just doing it has helped me get to a place where I'm able to build things I didn't think I could build, even just 6 months ago.

I've had many moments just grinding away, and then finally I'll see it spit out some html on the other side and I'm like "halleluyah!", and then I can put that particular problem in my tool chest of knowing how to solve that.

I think what you said about never arriving at the eureka! moment of complete confidence was good to hear. Because that's kind of what I've been striving for. My thought has been "If I'm a really great developer, I should be able to go from an idea to implementation without all these aggravations along the way." But maybe that'll never happen, which I should just get used to.

Recently, I've thought of maybe taking a dive into the fundamentals of object-oriented ruby programming and really starting to be a better rubyist in general(without RoR), which is something all the rails books kinda glossed over.