Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3751bd8
commit 4c23168
Showing
3 changed files
with
49 additions
and
49 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class PublicRecipesController < ApplicationController | ||
def index | ||
@recipes = Recipe.where(public: true).order(updated_at: :desc) | ||
end | ||
def index | ||
@recipes = Recipe.where(public: true).order(updated_at: :desc) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
class RecipesController < ApplicationController | ||
def index | ||
@recipes = current_user.recipes.all | ||
end | ||
|
||
def show | ||
@recipe = Recipe.find(params[:id]) | ||
end | ||
|
||
def new | ||
@recipe = Recipe.new | ||
end | ||
|
||
def create | ||
@recipe = current_user.recipes.build(recipe_params) | ||
|
||
respond_to do |format| | ||
format.html do | ||
if @recipe.save | ||
redirect_to recipes_url, notice: 'Recipe created successfully' | ||
else | ||
render :new, alert: 'Recipe not created. Please try again!' | ||
end | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@recipe = Recipe.find(params[:id]) | ||
|
||
if @recipe.destroy | ||
flash[:notice] = 'Recipe deleted successfully!' | ||
else | ||
flash[:alert] = 'Unable to delete recipe. Please try again later.' | ||
end | ||
redirect_to(recipes_path) | ||
end | ||
|
||
private | ||
|
||
def recipe_params | ||
params.require(:recipe).permit(:name, :description, :public, :preparation_time, :cooking_time) | ||
end | ||
end | ||
class RecipesController < ApplicationController | ||
def index | ||
@recipes = current_user.recipes.all | ||
end | ||
|
||
def show | ||
@recipe = Recipe.find(params[:id]) | ||
end | ||
|
||
def new | ||
@recipe = Recipe.new | ||
end | ||
|
||
def create | ||
@recipe = current_user.recipes.build(recipe_params) | ||
|
||
respond_to do |format| | ||
format.html do | ||
if @recipe.save | ||
redirect_to recipes_url, notice: 'Recipe created successfully' | ||
else | ||
render :new, alert: 'Recipe not created. Please try again!' | ||
end | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@recipe = Recipe.find(params[:id]) | ||
|
||
if @recipe.destroy | ||
flash[:notice] = 'Recipe deleted successfully!' | ||
else | ||
flash[:alert] = 'Unable to delete recipe. Please try again later.' | ||
end | ||
redirect_to(recipes_path) | ||
end | ||
|
||
private | ||
|
||
def recipe_params | ||
params.require(:recipe).permit(:name, :description, :public, :preparation_time, :cooking_time) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "PublicRecipes", type: :request do | ||
describe "GET /index" do | ||
RSpec.describe 'PublicRecipes', type: :request do | ||
describe 'GET /index' do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
end | ||
end |