Note that there are some explanatory texts on larger screens.

plurals
  1. POhas_may for a vote app
    primarykey
    data
    text
    <p>I'm new on rails and I'm trying to make my own simple vote application. I have two models:</p> <pre><code>class Product &lt; ActiveRecord::Base attr_accessible :description, :title, :photo has_many :votes has_attached_file :photo, :styles =&gt; { :medium =&gt; "300x300" } before_save { |product| product.title = title.titlecase } validates :title, presence: true, uniqueness: { case_sensitive: false } validates :photo, :attachment_presence =&gt; true end class Vote &lt; ActiveRecord::Base belongs_to :product attr_accessible :user_id end </code></pre> <p>here is the product controller</p> <pre><code>class ProductsController &lt; ApplicationController http_basic_authenticate_with :name =&gt; "dhh", :password =&gt; "secret", :except =&gt; [:index] def index @products = Product.all end def indexprv @products = Product.all end def show @product = Product.find(params[:id]) end def edit @product = Product.find(params[:id]) end def new @product = Product.new end def create @product = Product.new(params[:product]) if @product.save redirect_to @product else render 'new' end end def update @product = Product.find(params[:id]) if @product.update_attributes(params[:product]) flash[:success] = "Producto Actualizado" redirect_to root_path else render 'edit' end end def destroy Product.find(params[:id]).destroy flash[:success] = "Producto Eliminado." redirect_to root_path end end </code></pre> <p>I have many questions. </p> <p>How can I show the total votes per products on my index page of products?</p> <p>How can I create a button on my index product page to add a vote for a product?</p> <p>I don't know how to do this and I couldn't find any tutorial o blog with a similar example.</p> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload