Ir para conteúdo
  • ×   Você colou conteúdo com formatação.   Remover formatação

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

  • Conteúdo Similar

    • Por mikuzuhara
      Estes são os arquivos principais do projeto em ruby on rails:
       
      routes.rb:
       
      Rails.application.routes.draw do root to: 'recipes#index' resources :recipes resources :recipe_types end  
      recipe_type.rb:
       
      class RecipeType < ApplicationRecord has_many :recipes end recipe.rb:
       
      class Recipe < ApplicationRecord validates :title, :recipe_type, :cuisine, :difficulty, :cook_time, :ingredients, :cook_method, presence: true belongs_to :recipe_type def cook_time_min "#{cook_time} minutos" end end  
      create_recipes.rb:
       
      class CreateRecipes < ActiveRecord::Migration[5.2] create_table :recipe_types do |t| t.string :name t.timestamps end def change create_table :recipes do |t| t.string :title t.string :recipe_type t.string :cuisine t.string :difficulty t.integer :cook_time t.belongs_to :recipe_type t.timestamps end end end  
      create_recipe_type.rb:
       
      class CreateRecipeTypes < ActiveRecord::Migration[5.2] def change create_table :recipe_types do |t| t.string :name t.timestamps end create_table :recipes do |t| t.string :title t.string :recipe_type t.string :cuisine t.string :difficulty t.integer :cook_time t.belongs_to :recipe_type t.datetime :published_at t.timestamps end end end recipes_controller.rb:
       
      class RecipesController < ApplicationController def index @recipes = Recipe.all end def show @recipe = Recipe.find(params[:id]) end def new @recipe = Recipe.new end def create @recipe = Recipe.new(recipe_params) if @recipe.save redirect_to @recipe else flash[:alert] = 'Você deve informar todos os dados da receita' render :new end end def edit @recipe = Recipe.find(params[:id]) end def update @recipe = Recipe.find(params[:id]) if @recipe.update(recipe_params) redirect_to @recipe else flash[:alert] = 'Você deve informar todos os dados da receita' render :edit end end private def recipe_params params.require(:recipe).permit(:title, :recipe_type, :cuisine, :difficulty, :cook_time, :ingredients, :cook_method) end end  
      index.html.erb:
       
      <h1>CookBook</h1> <p>Bem-vindo ao maior livro de receitas online</p> <%= link_to 'Enviar uma receita', new_recipe_path %> <% @recipes.each do |recipe| %> <h1><%= link_to recipe.title, recipe %></h1> <ul> <li><%= recipe.recipe_type %></li> <li><%= recipe.cuisine %></li> <li><%= recipe.difficulty %></li> <li><%= recipe.cook_time_min %></li> </ul> <% end %>  
      Passo o seguinte comando rspec especificamente em visitor_visit_homepage_spec.rb linha 11:
       
      :~/workspace/cookbook_parte7$ rspec ./spec/features/visitor_visit_homepage_spec.rb:11 Run options: include {:locations=>{"./spec/features/visitor_visit_homepage_spec.rb"=>[11]}} Visitor visit homepage and view recipe (FAILED - 1) Failures: 1) Visitor visit homepage and view recipe Failure/Error: recipe = Recipe.create(title: 'Bolo de cenoura', difficulty: 'Médio', recipe_type: recipe_type, cuisine: 'Brasileira', cook_time: 50, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') ActiveModel::MissingAttributeError: can't write unknown attribute `recipe_type_id` # ./spec/features/visitor_visit_homepage_spec.rb:14:in `block (2 levels) in <top (required)>' Finished in 0.04808 seconds (files took 1.72 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/features/visitor_visit_homepage_spec.rb:11 # Visitor visit homepage and view recipe   E depois de fazer as mudanças nos arquivos recipe.rb e create_recipe.rb, executei o seguinte comando novamente:
      $ rails db:migrate RAILS_ENV=test
       
      Ao baixar o repositório na máquina, dei os seguintes comandos:
       
      $ rails generate migration RemoveRecipe_typeToRecipe recipe_type:string
      $ rails db:migrate RAILSENV=test
      $ rails generate model recipe_type name:string
      $ rails db:migrate RAILS_ENV=test
       
      Modifiquei os arquivos recipetype.rb e createrecipe_type.rb conforme mencionado acima e passei o mesmo rails db:migrate mencionado.
       
      Não estou entendendo o por que do erro, os relacionamentos entre as tabelas não estão feitos?
       
      Estou partipando do processo seletivo da Locaweb, e faltam 4 desafios para concluir a entrega dos desafios e o prazo vai até 28/10/2019.
       
      Aguardo por um comentário, dica ou sugestão.
       
      Obrigado,
       
      Marcelino
       
    • Por mikuzuhara
      Configuro a pasta do projeto da seguinte forma:
       
      :/workspace/cookbook_parte7/rails generate migration RemoveRecipe_typeToRecipes recipe_type:string
      :/workspace/cookbook_parte7/rails db:migrate RAILS_ENV=test
      :/workspace/cookbook_parte7/rails generate models recipe_type name:string
      :/workspace/cookbook_parte7/rails db:migrate RAILS_ENV=test
       
      Faço as alterações em recipe_type.rb e 20191023142828_create_recipe_types.rb conforme mostrado abaixo e passo o comando novamente:
       
      :/workspace/cookbook_parte7/rails db:migrate RAILS_ENV=test
       
      recipe_type.rb:
       
      class RecipeType < ApplicationRecord has_many :recipes, :class_name => :Recipe end 20191023142828_create_recipe_types.rb:
       
      class CreateRecipeTypes < ActiveRecord::Migration[5.2] def change create_table :recipe_types do |t| t.string :name t.timestamps end create_table :recipes do |t| t.belongs_to :recipe_type t.datetime :published_at t.timestamps end end end routes.rb:
       
      Rails.application.routes.draw do root to: 'recipes#index' resources :recipes, :recipe_types end recipes_controller.rb:
       
      class RecipesController < ApplicationController def index @recipes = Recipe.all end def show @recipe = Recipe.find(params[:id]) end def new @recipe = Recipe.new end def create @recipe = Recipe.new(recipe_params) if @recipe.save redirect_to @recipe else flash[:alert] = 'Você deve informar todos os dados da receita' render :new end end def edit @recipe = Recipe.find(params[:id]) end def update @recipe = Recipe.find(params[:id]) if @recipe.update(recipe_params) redirect_to @recipe else flash[:alert] = 'Você deve informar todos os dados da receita' render :edit end end private def recipe_params params.require(:recipe).permit(:title, :recipe_type, :cuisine, :difficulty, :cook_time, :ingredients, :cook_method) end end index.html.erb:
       
      <h1>CookBook</h1> <p>Bem-vindo ao maior livro de receitas online</p> <%= link_to 'Enviar uma receita', new_recipe_path %> <% @recipes.each do |recipe| %> <h1><%= link_to recipe.title, recipe %></h1> <ul> <li><%= recipe.recipe_type %></li> <li><%= recipe.cuisine %></li> <li><%= recipe.difficulty %></li> <li><%= recipe.cook_time_min %></li> </ul> <% end %> visitor_visit_homepage_spec.rb:
       
      require 'rails_helper' feature 'Visitor visit homepage' do scenario 'successfully' do visit root_path expect(page).to have_css('h1', text: 'CookBook') expect(page).to have_css('p', text: 'Bem-vindo ao maior livro de receitas online') end scenario 'and view recipe' do #cria os dados necessários recipe_type = RecipeType.create(name: 'Sobremesa') recipe = Recipe.create(title: 'Bolo de cenoura', difficulty: 'Médio', recipe_type: recipe_type, cuisine: 'Brasileira', cook_time: 50, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type.name) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") end scenario 'and view recipes list' do #cria os dados necessários recipe_type = RecipeType.create(name: 'Sobremesa') another_recipe_type = RecipeType.create(name: 'Prato principal') recipe = Recipe.create(title: 'Bolo de cenoura', difficulty: 'Médio', recipe_type: recipe_type, cuisine: 'Brasileira', cook_time: 50, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') another_recipe = Recipe.create(title: 'Feijoada', recipe_type: another_recipe_type, cuisine: 'Brasileira', difficulty: 'Difícil', cook_time: 90, ingredients: 'Feijão e carnes', cook_method: 'Misture o feijão com as carnes') # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type.name) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") expect(page).to have_css('h1', text: another_recipe.title) expect(page).to have_css('li', text: another_recipe.recipe_type.name) expect(page).to have_css('li', text: another_recipe.cuisine) expect(page).to have_css('li', text: another_recipe.difficulty) expect(page).to have_css('li', text: "#{another_recipe.cook_time} minutos") end end Passo o seguinte comando do rspec:
       
      :~/workspace/cookbook_parte7$ rspec ./spec/features/visitor_visit_homepage_spec.rb:11 Run options: include {:locations=>{"./spec/features/visitor_visit_homepage_spec.rb"=>[11]}} Visitor visit homepage and view recipe (FAILED - 1) Failures: 1) Visitor visit homepage and view recipe Failure/Error: visit root_path SyntaxError: /home/massa-90/workspace/cookbook_parte7/app/views/recipes/index.html.erb:8: syntax error, unexpected tIVAR, expecting '(' ...r.append=( @recipe.@recipe_type.name );@output_buffer.safe_a... ... ^~~~~~~~~~~~ # ./spec/features/visitor_visit_homepage_spec.rb:21:in `block (2 levels) in <top (required)>' Finished in 0.07533 seconds (files took 1.41 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/features/visitor_visit_homepage_spec.rb:11 # Visitor visit homepage and view recipe O que pode estar faltando no código para passar nesse teste?
       
      Aguardo retorno.
       
      Obrigado,
       
      Marcelino
       
    • Por mikuzuhara
      Esses são os arquivos principais do projeto:
       
      home_controller.rb:
       
      class HomeController < ApplicationController def index @recipes = Recipe.all end end routes.rb:
      Rails.application.routes.draw do root to: 'home#index' end recipe.rb
      class Recipe < ApplicationRecord def cook_time_min "#{cook_time} minutos" end end index.html.erb:
      <h1>CookBook</h1> <p>Bem-vindo ao maior livro de receitas online</p> <% @recipes.each do |recipe| %> <h1><%= recipe.title %></h1> <ul> <li><%= recipe.recipe_type %></a></li> <li><%= recipe.cuisine %></li> <li><%= recipe.difficulty %></li> <li><%= recipe.cook_time_min %></li> </ul> <% end %> Os arquivos spec.rb são estes:
      visitor_visit_homepage_spec.rb: 
      require 'rails_helper' feature 'Visitor visit homepage' do scenario 'successfully' do visit root_path expect(page).to have_css('h1', text: 'CookBook') expect(page).to have_css('p', text: 'Bem-vindo ao maior livro de receitas'\ ' online') end scenario 'and view recipe' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60) # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") end scenario 'and view recipes list' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60) another_recipe = Recipe.create(title: 'Feijoada', recipe_type: 'Prato Principal', cuisine: 'Brasileira', difficulty: 'Difícil', cook_time: 90) # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") expect(page).to have_css('h1', text: another_recipe.title) expect(page).to have_css('li', text: another_recipe.recipe_type) expect(page).to have_css('li', text: another_recipe.cuisine) expect(page).to have_css('li', text: another_recipe.difficulty) expect(page).to have_css('li', text: "#{another_recipe.cook_time} minutos") end end visitor_view_recipe_detail_spec.rb:
      require 'rails_helper' feature 'Visitor view recipe details' do scenario 'successfully' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') # simula a ação do usuário visit root_path click_on recipe.title # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('h3', text: 'Detalhes') expect(page).to have_css('p', text: recipe.recipe_type) expect(page).to have_css('p', text: recipe.cuisine) expect(page).to have_css('p', text: recipe.difficulty) expect(page).to have_css('p', text: "#{recipe.cook_time} minutos") expect(page).to have_css('h3', text: 'Ingredientes') expect(page).to have_css('p', text: recipe.ingredients) expect(page).to have_css('h3', text: 'Como Preparar') expect(page).to have_css('p', text: recipe.cook_method) end scenario 'and return to recipe list' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') # simula a ação do usuário visit root_path click_on recipe.title click_on 'Voltar' # expectativa da rota atual expect(current_path).to eq(root_path) end end Cheguei a fazer essa alteração em index.html.erb:
      <h1>CookBook</h1> <p>Bem-vindo ao maior livro de receitas online</p> <% @recipes.each do |recipe| %> <h1><%= recipe.title %></h1> <ul> <li><a href = "#detalhes"><%= recipe.recipe_type %></a></li> <li><%= recipe.cuisine %></li> <li><%= recipe.difficulty %></li> <li><%= recipe.cook_time_min %></li> </ul> <% end %> <a name = "detalhes"></a> <h1><%= recipe.title %></h1> <h3>Detalhes</h3> <p><%= recipe.recipe_type %></p> <p><%= recipe.cuisine %></p> <p><%= recipe.difficulty %></p> <p><%= recipe.cook_time %> minutos</p> <h3>Ingredientes</h3> <p><%= recipe.ingredientes %></p> <h3>Como Preparar</h3> <p><%= recipe.cook_method %></p> Mas acusou o seguinte erro no rspec:
      :~/workspace/cookbook_parte3$ rspec ./spec/features/visitor_visit_homepage_spec.rb:4 Run options: include {:locations=>{"./spec/features/visitor_visit_homepage_spec.rb"=>[4]}} Visitor visit homepage successfully (FAILED - 1) Failures: 1) Visitor visit homepage successfully Failure/Error: <h1><%= recipe.title %></h1> ActionView::Template::Error: undefined local variable or method `recipe' for #<#<Class:0x0000560710d070d8>:0x0000560710cfda60> Did you mean? @recipes # ./app/views/home/index.html.erb:15:in `_app_views_home_index_html_erb___4429749300272299021_47294173447260' # ./spec/features/visitor_visit_homepage_spec.rb:5:in `block (2 levels) in <top (required)>' # ------------------ # --- Caused by: --- # NameError: # undefined local variable or method `recipe' for #<#<Class:0x0000560710d070d8>:0x0000560710cfda60> # Did you mean? @recipes # ./app/views/home/index.html.erb:15:in `_app_views_home_index_html_erb___4429749300272299021_47294173447260' Finished in 0.08646 seconds (files took 1.45 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/features/visitor_visit_homepage_spec.rb:4 # Visitor visit homepage successfully A sintaxe de link_to é esse:
      linkto "textode_href", action = show, id = ?
      Onde tem ? na sintaxe, eu não sei o que por e em "textodehref" deve ir:
      recipe.title
      E adicionei os campos ingredientes e cook_method como segue:
      :~/workspace/cookbook_parte3$ rails generate migration add_attributes_to_recipe ingredients:string cook_method:string invoke active_record create db/migrate/20191021113942_add_attributes_to_recipe.rbmassa-90@ubuntu:~/workspace/cookbook_parte3$ rspecMigrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=test:~/workspace/cookbook_parte3$ cd bin:~/workspace/cookbook_parte3/bin$ rails db:migrate RAILS_ENV=test== 20191021113942 AddAttributesToRecipe: migrating ============================-- add_column(:recipes, :ingredients, :string) -> 0.0007s-- add_column(:recipes, :cook_method, :string) -> 0.0004s== 20191021113942 AddAttributesToRecipe: migrated (0.0014s) =================== A execução do rspec dos testes  do jeito que recebi o projeto do Code Saga original é este:
      :~/workspace/cookbook_parte3$ rspec Visitor view recipe details successfully (FAILED - 1) and return to recipe list (FAILED - 2) Visitor visit homepage successfully and view recipe and view recipes list Failures: 1) Visitor view recipe details successfully Failure/Error: recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') ActiveModel::UnknownAttributeError: unknown attribute 'ingredients' for Recipe. # ./spec/features/visitor_view_recipe_detail_spec.rb:6:in `block (2 levels) in <top (required)>' 2) Visitor view recipe details and return to recipe list Failure/Error: recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60, ingredients: 'Farinha, açucar, cenoura', cook_method: 'Cozinhe a cenoura, corte em pedaços pequenos, misture com o restante dos ingredientes') ActiveModel::UnknownAttributeError: unknown attribute 'ingredients' for Recipe. # ./spec/features/visitor_view_recipe_detail_spec.rb:31:in `block (2 levels) in <top (required)>' Finished in 9.35 seconds (files took 5.6 seconds to load) 5 examples, 2 failures Failed examples: rspec ./spec/features/visitor_view_recipe_detail_spec.rb:4 # Visitor view recipe details successfully rspec ./spec/features/visitor_view_recipe_detail_spec.rb:29 # Visitor view recipe details and return to recipe list Resumindo, o que preciso fazer para entregar esse desafio resolvido:
      1) Como implementar link_to no arquivo de controller; 2) Como referenciar o objeto recipe de @recipe para detalhar a receita em index.html.erb.
      Pago R$ 30,00 por desafio resolvido por alguém que se manifestar para me ajudar a solucioná-lo(s).
      Aguardo retorno.
      Obrigado,
      Marcelino
       
       
    • Por mikuzuhara
      Por favor, preciso de ajuda da comunidade Ruby. Sou recém chegado na linguagem Ruby e no framework Rails. Estou participando da Campus Code e não consigo progredir em um desafio proposto no treinamento. O repositório do projeto baixei em minha máquina virtual VMware com Ubuntu 18.04 e nele consta o projeto em Ruby on Rails e os testes para passar com rspec. Eis os arquivos sensíveis para concluir o projeto: 
       
      home_controller.rb:
      class HomeController < ApplicationController def page @recipes = Recipe.all end end page.html.erb:
      <% if recipes == [] %> <h1>CookBook</h1> <p>Bem-vindo ao maior livro de receitas online</p> <% else %> <% @recipes.each do |recipe| %> <h1><%= recipe.title %></h1> <li><%= recipe.recipe_type %></li> <li><%= recipe.cuisine %></li> <li><%= recipe.difficulty %></li> <li><%= recipe.cook_time %> minutos</li> <% end %> <% end %> recipe.rb:
      class Recipe < ApplicationRecord end routes.rb:
      Rails.application.routes.draw do root to: 'home#page' resources :recipe end  
      E esse é o arquivo de testes visitor_visit_homepage_spec.rb:
       
      require 'rails_helper' feature 'Visitor visit homepage' do scenario 'successfully' do visit root_path expect(page).to have_css('h1', text: 'CookBook') expect(page).to have_css('p', text: 'Bem-vindo ao maior livro de receitas'\ ' online') end scenario 'and view recipe' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60) # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") end scenario 'and view recipes list' do #cria os dados necessários recipe = Recipe.create(title: 'Bolo de cenoura', recipe_type: 'Sobremesa', cuisine: 'Brasileira', difficulty: 'Médio', cook_time: 60) another_recipe = Recipe.create(title: 'Feijoada', recipe_type: 'Prato Principal', cuisine: 'Brasileira', difficulty: 'Difícil', cook_time: 90) # simula a ação do usuário visit root_path # expectativas do usuário após a ação expect(page).to have_css('h1', text: recipe.title) expect(page).to have_css('li', text: recipe.recipe_type) expect(page).to have_css('li', text: recipe.cuisine) expect(page).to have_css('li', text: recipe.difficulty) expect(page).to have_css('li', text: "#{recipe.cook_time} minutos") expect(page).to have_css('h1', text: another_recipe.title) expect(page).to have_css('li', text: another_recipe.recipe_type) expect(page).to have_css('li', text: another_recipe.cuisine) expect(page).to have_css('li', text: another_recipe.difficulty) expect(page).to have_css('li', text: "#{another_recipe.cook_time} minutos") end end Passo o comando rspec na pasta do projeto:
       
      :~/workspace/cookbook_parte2$ rspec Visitor visit homepage successfully (FAILED - 1) and view recipe (FAILED - 2) and view recipes list (FAILED - 3) Recipe add some examples to (or delete) /home/massa-90/workspace/cookbook_parte2/spec/models/recipe_spec.rb (PENDING: Not yet implemented) Pending: (Failures listed here are expected and do not affect your suite's status) 1) Recipe add some examples to (or delete) /home/massa-90/workspace/cookbook_parte2/spec/models/recipe_spec.rb # Not yet implemented # ./spec/models/recipe_spec.rb:4 Failures: 1) Visitor visit homepage successfully Failure/Error: <% if recipes == [] %> ActionView::Template::Error: undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a9f30b8> Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' # ./spec/features/visitor_visit_homepage_spec.rb:5:in `block (2 levels) in <top (required)>' # ------------------ # --- Caused by: --- # NameError: # undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a9f30b8> # Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' 2) Visitor visit homepage and view recipe Failure/Error: <% if recipes == [] %> ActionView::Template::Error: undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a68c0c8> Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' # ./spec/features/visitor_visit_homepage_spec.rb:19:in `block (2 levels) in <top (required)>' # ------------------ # --- Caused by: --- # NameError: # undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a68c0c8> # Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' 3) Visitor visit homepage and view recipes list Failure/Error: <% if recipes == [] %> ActionView::Template::Error: undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a4b2cc0> Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' # ./spec/features/visitor_visit_homepage_spec.rb:41:in `block (2 levels) in <top (required)>' # ------------------ # --- Caused by: --- # NameError: # undefined local variable or method `recipes' for #<#<Class:0x0000564c2a9f8630>:0x0000564c2a4b2cc0> # Did you mean? @recipes # ./app/views/home/page.html.erb:1:in `_app_views_home_page_html_erb___526898541735595527_47442566303380' Finished in 0.34634 seconds (files took 2.17 seconds to load) 4 examples, 3 failures, 1 pending Failed examples: rspec ./spec/features/visitor_visit_homepage_spec.rb:4 # Visitor visit homepage successfully rspec ./spec/features/visitor_visit_homepage_spec.rb:12 # Visitor visit homepage and view recipe rspec ./spec/features/visitor_visit_homepage_spec.rb:29 # Visitor visit homepage and view recipes list E para criar a model recipe na linha do terminal e executar a migration criada em db/migrations:
       
      $ rails generate model recipe title:string recipe_type:string cuisine:string difficulty:string cook_time:string invoke active_record create db/migrate/20191016221038_create_recipes.rb create app/models/recipe.rb invoke rspec create spec/models/recipe_spec.rb $ rspec Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=test $ cd bin $ rails db:migrate RAILS_ENV=test== 20191016221038 CreateRecipes: migrating ==================================== -- create_table(:recipes) -> 0.0029s == 20191016221038 CreateRecipes: migrated (0.0035s) =========================== O que pode ser alterado nos códigos do projeto que eu não saiba?
       
      Aguardo sua resposta.
       
      Obrigado,
       
      Marcelino
       
    • Por systemtiago
      Tenho o seguinte configuração
      module  Account   class Permission < ApplicationRecord   end end module Account   class GroupPermission < ApplicationRecord     belongs_to :permission   end end Table:  account_group_users
                 account_users_id bigint,
                 account_groups_id bigint,
      Table:  account_group_permissions
             account_permissions_id bigint,
            account_groups_id bigint,
      Quando tento acessar  a instancia Account::GroupPermission  e por ela acessar Account::Permission  retorna nil.
      Só funciona se eu especificar o class_name:
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.