I am still working on my website with a database containing items. In my model I've got parameters for records like: 'type' (melee, ranged, etc.etc.), 'ammunition', 'weight', 'damage' and etc. Now not every record has the same parametres, some have ammunition and some don't (they are just blank). Now I am trying to create a site in html.erb that shows the scope for the type of item we've choosen before by clicking the type button on index page. Let's say that we choose Melee weapons so it redirects us to page and the table only contains name, damage and weight. Next time we choose ranged and now the same page displays a table with name, damage, weight, AND ammunition capacity. Is this possible to do or do I have to create separate pages for every scope I have? If it is possible then can anyone help me with it, please?
Here's my model:
class Items < ActiveRecord::Base
has_attached_file :icon, :styles => { :medium => "300x300>", :thumb => "24x24>" },
default_url: "/assets/items/missing.png",
url: "/assets/items/:id/:style/:basename.:extension",
path: ":rails_root/public/assets/items/:id/:style/:basename.:extension"
validates_attachment_content_type :icon, :content_type => /\Aimage\/.*\Z/
scope :melee, -> { where(type: 'Melee')}
scope :ranged, -> { where(type: 'Ranged')}
scope :accs, -> { where(type: 'Accessories')}
scope :ves, -> { where(type: 'Vests')}
end
And here's the controller for the page:
def db_showspec
@item = Items.melee
end
Once again sorry for my poor English!