RoR - How To Count & Display Comments [closed] - ruby-on-rails-3

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm looking to have a count of the number of comments left under an article and display it on the index page beside that particular article - like the example here in red circles. Any suggestions as to how I might do this?
The picture is an example of what I'm trying to do, its not my site.

This sounds like a good candidate for Rails.cache. Every time you create a new comment simply increment that cache counter using the post id.
If the cache entry does not exist, do a simple article.comments.count (depends on your domain model of course) query and re-cache it.

Storing it in a cache is one idea, yes.
But storing it in a counter_cache column is probably a better idea. That way even if your server was restarted somehow you wouldn't loose the cached values. See http://guides.rubyonrails.org/association_basics.html, section 4.1.2.4.

Related

How can I represent this idea to the database design? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new to database design, I am trying to build a database of shopping system.
Assume we have a Customer table and a Staff table.
The requirement is:
To allow part of the customers to have privilege of "Item return & refund".
To allow part of the staff to have the authority to process the refund.
My idea is to simply add a column with a Boolean value to "Flag" which customer or which staff has the authority or not?
Is that correct to solve this problem? Any potential problem?
This would be correct for a simplistic design. However, if you want to be able to expand on your website or if your needs grow over time, you may need to allow for more detailed permissions. A user_permissions table and an employee_permission table would be desirable in that case.

SQL does replace and CAST on select affect the Database? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am creating a view and I was asked to do a 'replace' and a 'cast', so as an example:
SELECT CAST(qtyshipped AS INT) AS 'QTYShipped', REPLACE(itemval,'.','')
FROM Database
Within the view, should not actually change the information in the database but just in the query correct? (It works perfectly in my sandbox server but i just want to confirm)
Not a dumb question at all. And the answer is yes, it only changes the result of the query, the underlying data will remain the same.
That is already a good query. But I need to tell some points with you.
REPLACE function is case-sensitive. Although I've seen in your code that you are only replacing period.
Why is your column qtyshipped is not in numeric type? You should have change that into numeric. So you won't need casting which may lower the performance.
It will not affect your database since your are only executing SELECT not UPDATE.

Show data from multiple tables by date and time [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have these tables: Idea and poll (and others) which are types of what can a member post within a community. I need to show them all in the "Activity stream" ordered by time and date, so a member can see in his "Activity stream" all what others have posted whatever is the type. I've looked around and have found to use the UNION, however they said this way is too slow. I thought to create another table named posts that contains the ID of the post and its time and date, updated in each new post. But either this way costs me a new table. What do you think is the best way? Any other suggestion will be appreciated.
Yes it is, like "Tom asked a question:__ in:__ few minutes a go"
So you need a user name, an action, a timestamp and a hidden id.
Well performance-wise a separate table is better (you avoid unions and maybe joins if it's not necessary to be mormalized), but you have the extra storage (is this an issue?) and the overhead of inserting new records to this table (tiny). Be aware for the usage of a switch to get the details of each activity from its origin table.
Bottom line everything depends on the data volume and the traffic.

Check whether Old and New Passwords are similar (ASP.NET) [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a Password Reset Functionality ,I have to check whether Old and New Passwords are
similar, If similar or same through error .
If,
Old Password : BradPitt
New Password :JohnPitt
Here passwords are similar
What I have to do is, I have to check whether PASSWORDS ARE ATLEAST 50% SIMILAR. in ASP.NET
This can get very complicated. It all depends on how you define "similar". Once you have that, the rest becomes easier.
Here it may mean: a password is seen as similar if it starts with or ends with the same sequence of at least n characters (say, 4) than the previous one.
Or it may mean: if you count +1 for every place where the character in the old password is the same as in the new password, and have at least 50% of the number of characters the same. In that case, "BradPitt" and "JohnPitt" would be similar, but "BradPitt" and "McDonaldPitt" would not.
So the first thing to do is to define similarity. Implementing it then becomes a snap.
Good luck!

Is there a blog search api? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm looking for an API, or a solution, to find blog posts on the web.
I have few keywords passed by a user (like "fashion hats") and I want to get a list of blog posts that match it.
Importants is the freshness of the post and the relevancy of the source.
Is anything already out there?
Thanks a lot
It's hard to select for date and for relevance at the same time. Here's how you do it with blekko:
https://blekko.com/ws/hats+/fashion+/blog+/daterange=%221+month+ago-now%22
This shows, sorted by relevance, the search string [hats] limited to the human-curated slashtag /fashion, reduced by the algorithmic slashtag /blogs, within the last month.
Alternately, you can sort by date instead of relevance:
https://blekko.com/ws/hats+/fashion+/blog+/date=%221+month+ago-now%22
Our free API can be used to fetch these results -- contact us at apiauth#blekko.com for details.
I'd point you at some interesting URLs that list the good human-curated slashtags and clues about other advanced slasthag usage, but Stack Overflow's reputation system says I'm too much of a n00b to do so.
I know of at least two: 1) yahoo boss which costs .10 per thousand results, and blekko also has an api that can search blogs. You'll need to inquire about the specifics directly with blekko at apiauth#blekko.com.