Use stock quotes from stock_sort gem as a tag from act_as_taggable gem?

So, I am using tags provided by act_as_taggable gem. Posts is what I’m tagged. How can I say something (pseduocode here) e.g. =>

if a collection of Posts has a tag with a corresponding StockQuote, display the stock quote 

So now I have a Post resource that acts like act_as_taggable. Here's what the message index action looks like:

 def index @stock = StockQuote::Stock.quote("symbol") if params[:tag] @posts = Post.tagged_with(params[:tag]) else @posts = Post.order('cached_votes_score desc') end end 

So I would need to iterate over all the @posts tags tagged_with params [: tag] tags and compare the tags with stock quotes. And show the quote on the index of all @posts tagged_with params [: tag] if there is a match. I will try to figure out how to limit each post so that there is 1 tag soon

How can I use the tag: tag to access the stock quote, if this tag is a stock quote?

+6
source share
1 answer

I think you would like to do something like:

 @symbols = @post.tag_list @quotes = StockQuote::Stock.quote(@symbols) 

Since a message can really be marked with several characters, you will want to immediately extract them, and then iterate over the result in the view. Sort of:

 <% @quotes.each do |quote| %> <%= "#{quote.symbol}: #{quote.ask}" %> <% end %> 

I am not very familiar with gems, but with a quick glance it seems something like this will work.

In addition, you formulate the question as if you had a special instance of the message, but then show the action of the index, which pulls out a collection of messages. The example I provided will work for a unique Mail (the user is viewing the message page).

0
source

Source: https://habr.com/ru/post/990025/


All Articles