Ruby on Rails Saturday, July 20, 2013

On Jul 20, 2013, at 10:21 PM, Giannakis P. <lists@ruby-forum.com> wrote:

> Hello Robert :)
>
> No no, i need a clear category table. Here's what i done
>
> I generated a migration
>
> class AddCategoriesToPins < ActiveRecord::Migration
> def change
> add_column :pins, :category, :string
> end
> end
>
> in my Pin Uploading form i added
>
> <%= f.select :category, [ 'Box', 'Cover', 'Poster' ], :prompt => 'Select
> One' %>
>
> Now, the Selecting a Category when uploading Works, and the category
> shows up properly in the Database.
>
> But i want the user to click on that category in the Show Page and see
> all the pin's that are in that category.
>
> P.S.: Is this method even a good one ? I dont want the user's to be able
> to create, edit, or delete a Category. Just selecting it.


This can certainly work, though seems less flexible in the long run as to update categories you have to go into the code base and make the change there, rather than have a configurable set in a table.

But even with this, it's quite possible, but again, you're necessarily hard coding the selection instead of drawing it from a table. In you category navigation, you offer the user the ability to select on of Box, Cover or Poster, and then use gather them in the appropriate controller with pins = Pin.where(:category => params[:category]) for example (depending on how you actually get the user's desired category).


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/E94B359C-5F04-4D40-99B9-FD44CB84C6D0%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment