Last active
December 30, 2015 17:39
-
-
Save JRizzle88/7862465 to your computer and use it in GitHub Desktop.
Couldn't find Studio without an ID , Trying to create new studio when button is clicked in the products view. The error is pointing to def set_studio @studio = Studio.find(params[:id])
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
### PRODUCTS VIEW ### | |
<%= button_to 'Customize', new_studio_path, method: :get, :class => 'button [tiny small large] middle pos-10-top' %> |
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] | |
# GET /products | |
# GET /products.json | |
def index | |
@products = Product.all.paginate page: params[:page], | |
per_page: 12 | |
end | |
# GET /products/1 | |
# GET /products/1.json | |
def show | |
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 [:admin, @product], | |
notice: 'Product was successfully created.' } | |
format.json { render action: 'show', | |
status: :created, location: @product } | |
else | |
format.html { render action: '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 [:admin_products, @products], | |
notice: 'Product was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @product.errors, | |
status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /products/1 | |
# DELETE /products/1.json | |
def destroy | |
@product = Product.find(params[:id]) | |
@product.destroy | |
respond_to do |format| | |
format.html { redirect_to [:admin_products, @products] } | |
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(:title, :description, :image_url, :price) | |
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
Verone::Application.routes.draw do | |
devise_for :users, :controllers => {:registrations => "registrations"} | |
devise_for :admins | |
get '/token' => 'home#token', as: :token | |
namespace :admin do | |
get 'dashboard' => 'dashboard#index' | |
root :to => "dashboard#index" | |
resources :admin | |
resources :posts | |
resources :products | |
resources :users | |
resources :orders | |
resources :studios | |
resources :post_categories | |
resources :product_categories | |
end | |
root :to => "home#index" | |
resources :posts do | |
resources :comments | |
end | |
get "/store/index" | |
resources :products | |
resources :line_items | |
resources :orders | |
resources :carts | |
resources :studios | |
resources :post_categories | |
resources :product_categories | |
resources :list_items | |
resources :stores, as: 'store' | |
#get "/store/index" | |
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
class StudiosController < ApplicationController | |
before_action :set_studio | |
before_action :studio_params | |
# GET /studios | |
# GET /studios.json | |
def index | |
@studios = Studio.all | |
end | |
# GET /studios/1 | |
# GET /studios/1.json | |
def show | |
@studio = Studio.find(studio_params) | |
end | |
# GET /studios/new | |
def new | |
@studio = Studio.new(params[:id]) | |
end | |
# GET /studios/1/edit | |
def edit | |
end | |
# POST /studios | |
# POST /studios.json | |
def create | |
@studio = Studio.new(studio_params) | |
respond_to do |format| | |
if @studio.save | |
format.html { redirect_to @studio, notice: 'Studio was successfully created.' } | |
format.json { render action: 'show', status: :created, location: @studio } | |
else | |
format.html { render action: 'new' } | |
format.json { render json: @studio.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /studios/1 | |
# PATCH/PUT /studios/1.json | |
def update | |
respond_to do |format| | |
if @studio.update(studio_params) | |
format.html { redirect_to @studio, notice: 'Studio was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @studio.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /studios/1 | |
# DELETE /studios/1.json | |
def destroy | |
@studio.destroy | |
respond_to do |format| | |
format.html { redirect_to studios_url } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_studio | |
@studio = Studio.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def studio_params | |
params.require(:studio).permit(:name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment