In week 4 video I see that we create the link between a hashtag using gsub on specific text where it has #. It goes on to further state that we are passing the text. In the controller I noticed that in order to find the hashtag it uses the params[:id] (code below).
I find this a tad confusing as from what I can gather the hashtag itself does not have an ID it is simply matched text.
So in short where does this ID come from and why is it not being matched by params[:text].
Apologies if I am missing something really clear here.
class HashTagsController < ApplicationController
@hashtag = params[:id]
@shouts = Shout.search(@hashtag)
The params hash is created by the link or button that calls this action. In the case of SHOW, the resource will be found in the database by that id in the params.
so if you had a link that goes to “/hash_tags?id=12”, rails will use the hashtags controller, and since the action is a GET and there was an ID passed in the params, Rails knows we want to express the SHOW action with that hashtag.
If you do not have the param[:id] from the previous location you will need to add it. Also, if you call a show action and don’t pass an ID in the params, you will get a route not found.
I think what I am more confused by is the fact the hash is not stored in its own table it is extracted from the shout. I presume the ID is being used to collect all the shouts with said hashtag.
Got a link to the source you are talking about? I can look into the class and see if there is any better ‘splainin’ I could do
Hey think I got it now. Thanks though.