Showing chronology of jobs rails - ruby-on-rails

I am trying to add some chronology to my 'jobs' so that when someone posts a job it lists conveniently under the date in which it was created and other posts will then go above it based on recency. An example of this can be seen on Dribble Jobs.
I am not really sure how to best approach this as it is something I haven't done before, any suggestions on how to achieve it would be much appreciated!

You can use Rails timestamps, which will make this very, very easy. Just use the created_at timestamp for the jobs, and order by that (or perhaps the id field).

Related

What is the best practice for comparing against the current time in Rails?

In the app I'm working on we compare against Time.now in some places, and Database.time in others. I would like to use only one of these throughout the whole application. Unfortunately I haven't been able to find much information on them through google searches. Which is preferred? How are they different from each other? Thanks!
There are a couple of articles on thoughtbot's blog that cover this:
https://robots.thoughtbot.com/its-about-time-zones
https://robots.thoughtbot.com/a-case-study-in-multiple-time-zones
Hopefully those help.
The function Time.now gives you the time in the application server running your Rails app request. This is reliable in most cases.
Rails uses the app server time when filling the updated_at and created_at columns of its models.
I'm not sure about the Database.time function you are referring to... This is probably a class defined in your code or inherited from gem in your app. Because of that I would suggest moving to the Ruby core time functions. In your case: Time.now

How to Sort table rows in Rails ? (the best way)

I am going through railscast http://railscasts.com/episodes/228-sortable-table-columns but since it is 3 year old video I was wondering, is this still the best way to sort in rails ? I found https://github.com/thoughtbot/sortable_table but this is not maintained anymore.
I recommend going with a much more up to date solution datatables which will do exactly what you want and more! You can sort, search and select multiple tables. A full documentation is available detailing different options.

Web-based form-builder for users in Ruby/Rails

First time posting in Stack Overflow, hope I'm doing this right.
I'm writing an app with Ruby on Rails right now. Without disclosing too much, the premise is that we have organizations and normal users. Organizations have events, which require users to answer a questionnaire before participating.
I'm pretty sure about these models / relationships that I will be using (this isn't really that important/pertinent to my question i think, but just wanted to give background):
organization (one to many) events
event (one to one) quesitonnaire)
questionnaire (one to many) users
(specific) response (one to one) user
The part I have a question about is how to implement the questionnaire. I want to give the ability to Organizations to essentially write / build their own forms. I'd like to stay away from them using code if that's possible (ie any DSL and whatnot).
I suppose the easiest way to do this is to give them a set number of text-area responses, so that I can consistently store the data and don't have to hassle around with how to configure storing this data (for example, maybe each event can only have exactly 5 responses to be filled in by textfield response by the user).
My ideal would be for the organization to be able to dynamically generate the forms on their own - maybe one questionnaire will have 1 text input, followed by 3 multiple choices, and maybe 2 short answers at the end; another one may have 5 multiple choices, and 1 short answer; yet another questionnaire might only have 1 text input...you get the idea.
So I see two parts of this problem - the first is the user interface for the organization to create the questionnaire. i'm imagining this wouldn't be terribly hard - ask them how many of each response type (MC, short answer) they would like to put into the form, give them the ability to rearrange them, etc.
The second part of the problem (what I'm more concenred about) is how to store/access this data. I'm guessing there's no dynamic-attribute sort of deal in ruby - storing some field with an unspecified number of parts and whatnot. i suppose i could make them all individual models (ie a question_response model, with :question, :response_type, :response, etc), but I'm fairly certain that's probably inefficient.
My initial guess is probably to serialize the data / use json; I worked briefly with Drupal 6 and this seems to be the way they did it. I was wondering if anyone else had any experience / suggestions though? I'm pretty new to Ruby so I was wondering if there's a gem out there or something that would help with what I'm trying to do.
Thanks!
You might want to look at the Surveyor gem
http://vimeo.com/7051279
*slightly old how-to video
https://github.com/breakpointer/surveyor
Surveyor does come with it's own DSL which is relatively easy to use (although can be abit restrictive at times). The data is saved as a set of question - answer values, so there is no actual specific model (beyond Surveys -> Questions (question_groups) -> Answers).
Originally I did look at having people submit their own Surveyor DSL specs - which would then be used to generate the actual survey via a Rake command.
I think if you need to build a dynamic model (and save the data) it is possible, although I am not not sure if you'll be able to get the Rake tasks to run to build the actual tables in a dynamic way due to permission restrictions.
Have a look at http://ruby-metaprogramming.rubylearning.com/ and Metaprogramming Ruby: Program Like the Ruby Pros by Paolo Perrotta, for some starters.

Good approach to a tagging system in Rails 3?

I'm trying to add tagging to my rails app - I'd rather not use a plugin/gem for this though.
My needs are pretty simple:
Users can add multiple tags to a single item, they can search for items by those tags, and they can see a page which lists all the tags they've used before.
What I'm wondering is, whats the best way to go about this? An array/hash in the model being tagged? A join table?
Any suggestions would be highly appreciated.
I would use a join table between the tags and the taggableItems. Then with a before_create you could check if the tag's are already in the system and create them if they aren't in the system. Next you could use searchlogic (i think there is a rails 3 branch on github) for easy tag/taggableItems searching. And it would be nice to give the user some feedback of the available tags with some autocompletion or a short list of most used tags but that is up to you/the design.
Maybe this helps you: Best Rails Tagging Plugin/Gem

rails smart collection

What are rails smart collections?
If I am trying to build a view that presents most popular articles, top 10 products, recent comments (i.e a snapshot of recent updates to a variety of models in one view), would I be using a smart collection?
Would I be updating it via something like delayed job? Use some sort of fragment caching?
What's the best way of doing this?
Thanks
I've never heard of 'smart collections'. That reference to them in the delayed_jobs docs seems to be the only one out there. It would probably be better to email the author, he might have been referring to something that exists only in his head :)

Resources