Created
September 11, 2015 09:12
-
-
Save AttyC/f798a37f85a7b037f984 to your computer and use it in GitHub Desktop.
comment path undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr> | |
<td><%= product.name %></td> | |
<td><%= product.description %></td> | |
<td><%= product.image_url %></td> | |
<td><%= product.colour %></td> | |
<td><%= link_to 'Show', product %></td> | |
<td><% if signed_in? && current_user.admin? %> | |
<%= link_to 'Edit', edit_product_path(product) %> | |
<% end %> | |
</td> | |
<td><% if signed_in? && current_user.admin? %> | |
<%= link_to ('<span class="glyphicon glyphicon-remove"</span>').html_safe, product_comment_path(@product, comment), method: :delete, data: { confirm: 'Are you quite sure?' } %> | |
<% end %></td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Showing /home/ubuntu/workspace/app/views/products/_product.html.erb where line #13 raised: | |
undefined local variable or method `comment' for #<#<Class:0x00000004c4a140>:0x000000046aa500> | |
Extracted source (around line #13): | |
11 | |
12 | |
13 | |
14 | |
15 | |
<td><% if signed_in? && current_user.admin? %> | |
<%= link_to ('<span class="glyphicon glyphicon-remove"</span>').html_safe, product_comment_path(@product, comment), method: :delete, data: { confirm: 'Are you quite sure?' } %> | |
<% end %></td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductsController < ApplicationController | |
before_action :set_product, only: [:show, :edit, :update, :destroy] | |
before_filter :authenticate_user! | |
# GET /products | |
# GET /products.json | |
def index | |
if params[:q] | |
search_term = params[:q] | |
@products = Product.where("name LIKE ?", "%#{search_term}%") | |
else | |
@products = Product.all.paginate(page: params[:page], per_page: 5) | |
end | |
end | |
# GET /products/1 | |
# GET /products/1.json | |
def show | |
@comments = @product.comments.all.order("created_at DESC").paginate(page: params[:page], per_page: 3) | |
end | |
# GET /products/new | |
def new | |
@product = Product.new | |
end | |
# GET /products/1/edit | |
def edit | |
end | |
# POST /products | |
# POST /products.json | |
def create | |
@product = Product.new(product_params) | |
respond_to do |format| | |
if @product.save | |
format.html { redirect_to @product, notice: 'Product was successfully created.' } | |
format.json { render :show, status: :created, location: @product } | |
else | |
format.html { render :new } | |
format.json { render json: @product.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /products/1 | |
# PATCH/PUT /products/1.json | |
def update | |
respond_to do |format| | |
if @product.update(product_params) | |
format.html { redirect_to @product, notice: 'Product was successfully updated.' } | |
format.json { render :show, status: :ok, location: @product } | |
else | |
format.html { render :edit } | |
format.json { render json: @product.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /products/1 | |
# DELETE /products/1.json | |
def destroy | |
@product.destroy | |
respond_to do |format| | |
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_product | |
@product = Product.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def product_params | |
params.require(:product).permit(:name, :description, :image_url, :colour) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'} | |
resources :users | |
controller :static_pages do | |
get :home | |
get :about | |
get :contact | |
end | |
post 'static_pages/thank_you' | |
#get 'thank_you' => 'static_pages#thank_you' | |
get 'landing_page' => 'static_pages#landing_page' | |
get 'featured_page' => 'static_pages#featured_page' | |
get 'contact' => 'static_pages#contact' | |
get 'about' => 'static_pages#about' | |
#get 'users/index' => 'users#index' | |
#get 'users/show' => 'users#show[:id]' | |
#get '/products', to: 'products#new' #redirected products url to orders, for fun! | |
resources :products do | |
resources :comments | |
end | |
# created with scaffolding - shows all default CRUD routes | |
# The priority is based upon order of creation: first created -> highest priority. | |
# See how all your routes lay out with "rake routes". | |
# You can have the root of your site routed with "root" | |
root 'static_pages#index' | |
# Example of regular route: | |
# get 'products/:id' => 'catalog#view' | |
# Example of named route that can be invoked with purchase_url(id: product.id) | |
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | |
resources :orders, only: [:index, :show, :new, :create] | |
# Example resource route (maps HTTP verbs to controller actions automatically): | |
# resources :products | |
# Example resource route with options: | |
# resources :products do | |
# member do | |
# get 'short' | |
# post 'toggle' | |
# end | |
# | |
# collection do | |
# get 'sold' | |
# end | |
# end | |
# Example resource route with sub-resources: | |
# resources :products do | |
# resources :comments, :sales | |
# resource :seller | |
# end | |
# Example resource route with more complex sub-resources: | |
# resources :products do | |
# resources :comments | |
# resources :sales do | |
# get 'recent', on: :collection | |
# end | |
# end | |
# Example resource route with concerns: | |
# concern :toggleable do | |
# post 'toggle' | |
# end | |
# resources :posts, concerns: :toggleable | |
# resources :photos, concerns: :toggleable | |
# Example resource route within a namespace: | |
# namespace :admin do | |
# # Directs /admin/products/* to Admin::ProductsController | |
# # (app/controllers/admin/products_controller.rb) | |
# # end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment