top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create Categories in Rails

0 votes
351 views

I'm trying to Add Categories to my Rails app, but don't quite know how to do this.

I have many Pins(Images) and want the user to be able to assign a category on those Pins. ASSIGN not create, edit, or delete a Category, just selecting one for their Pin. Meaning that, When a user uploads a
pin, he can choose from a dropdown list a Category.

Then, another user can choose from the Menu a Category, and ONLY the Pins in this Category will be listed. How can i do this? Any pointer??

posted Jul 20, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

It sounds as though you are going to limit them to one category per pin.

Simply using that, a given pin will belong to a category, and a category will have many pins. This should tell you the relationship to use. Read the rails guide on relationships for how to set this up.

Since you are not allowing the user to define categories, you will need, as an admin or as part of your app configuration, to fill in the categories you want your users to be able to select from.

answer Jul 21, 2013 by anonymous
Similar Questions
+1 vote

I'm a little confused about how one is supposed to create an ordered hash.

As far as I can tell, ActiveSupport::OrderedHash does not provide a constructor or a method that can create a hash from an array of pairs. Is this a deliberate ommission?

Hash also doesn't provide this, although later versions of ruby provide .to_h on an array as a way of generating a hash.

Why isn't there an OrderedHash.from_a( method? Why not, perhaps, have ActiveSupport patch Array to provide a ".to_ordered_h" method on an array? If there's an obvious way to create an ordered hash, please let me know about it. FWIW, my particular application was converting an ordered CsvRow to an ordered hash, which seem to involve my code than I felt should be necessary.

+2 votes

I am trying to write a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure dont play nice with time zones.

I have an appointment model with the appointment_time attribute which is a datetime. My current issue is editing appointment_time with datetime_select within a form tag.

def appt_time
appointment_time.in_time_zone(time_zone) #this is the appointment owners time zone 
end

This gives a select with the current date and time in UTC, not the appointment date and time. appt_time does get called and returns the correct date and time adjusted for the time zone.

The docs mention nothing about time zones, what is the best way to accomplish this?

+1 vote

Something like x.instance_variables.each.... { |i} .... }

Thought to be a one liner. I can't figure out how to apply strip() to each variable, since instance_variable_get returns the value. I really want something I can apply .strip! to....

+2 votes

I have a table with several thousand records in it. They take a long time to load and are essentially useless presented altogether.. I'd like present the user a search form to select a limited subset of records for display in the index function. What options are available to solve this problem and where might I look for examples or demos?

...