Jump to content
wanderson Luan

maquina virtual, com problema.

Recommended Posts

olá pessoal, estou com um problema, na minha maquina virtual, pois quando levanto a aplicação, não sobe para a web, com o localhost:3000.

 

e ele está criando um erro gigantesco, e saindo quando dou o comando rails s -b 0.0.0.0 no meu terminal. nesse caso estou usando o "foreman start".

vagrant@precise32:/vagrant/escamboapp$ foreman start
18:11:26 web.1  | started with pid 7947
18:11:57 web.1  | /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.5/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for Install (call 'Install.connection' to establish a connection):Class (NoMethodError)
18:11:57 web.1  |       from /vagrant/escamboapp/app/models/install.rb:4:in `<class:Install>'
18:11:57 web.1  |       from /vagrant/escamboapp/app/models/install.rb:1:in `<top (required)>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `load'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `block in load_file'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:647:in `new_constants_in'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:456:in `load_file'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:354:in `require_or_load'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:494:in `load_missing_constant'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184:in `const_missing'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:261:in `const_get'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:261:in `block in constantize'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `each'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `inject'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `constantize'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:566:in `get'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:597:in `constantize'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise.rb:313:in `get'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/mapping.rb:81:in `to'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/mapping.rb:76:in `modules'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/mapping.rb:93:in `routes'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/mapping.rb:160:in `default_used_route'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/mapping.rb:70:in `initialize'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise.rb:343:in `new'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise.rb:343:in `add_mapping'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/rails/routes.rb:241:in `block in devise_for'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in `each'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in `devise_for'
18:11:57 web.1  |       from /vagrant/escamboapp/config/routes.rb:2:in `block in <top (required)>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `instance_exec'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `eval_block'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:412:in `draw'
18:11:57 web.1  |       from /vagrant/escamboapp/config/routes.rb:1:in `<top (required)>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `each'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `load_paths'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:16:in `reload!'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:26:in `block in updater'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/file_update_checker.rb:75:in `execute'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:27:in `updater'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `call'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
18:11:57 web.1  |       from /usr/share/ruby-rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
18:11:57 web.1  |       from /vagrant/escamboapp/config/environment.rb:5:in `<top (required)>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
18:11:57 web.1  |       from /vagrant/escamboapp/config.ru:3:in `block in <main>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/builder.rb:55:in `instance_eval'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/builder.rb:55:in `initialize'
18:11:57 web.1  |       from /vagrant/escamboapp/config.ru:in `new'
18:11:57 web.1  |       from /vagrant/escamboapp/config.ru:in `<main>'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/builder.rb:49:in `eval'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/builder.rb:49:in `new_from_string'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/builder.rb:40:in `parse_file'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/server.rb:300:in `build_app_and_options_from_config'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/server.rb:209:in `app'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/rack-1.6.8/lib/rack/server.rb:337:in `wrapped_app'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
18:11:57 web.1  |       from /home/vagrant/.rvm/gems/ruby-2.3.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
18:11:57 web.1  |       from bin/rails:4:in `require'
18:11:57 web.1  |       from bin/rails:4:in `<main>'
18:11:57 web.1  | => Booting WEBrick
18:11:57 web.1  | => Rails 4.2.5 application starting in development on http://0.0.0.0:3000
18:11:57 web.1  | => Run `rails server -h` for more startup options
18:11:57 web.1  | => Ctrl-C to shutdown server
18:11:57 web.1  | Exiting
18:11:57 web.1  | exited with code 1
18:11:57 system | sending SIGTERM to all processes

 

 

Agradeço desde já!

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Hacker_Buiu
      Fiz os programas no Lazarus(Delphi 7 para Linux):

      Calculadora Completa:



      Download do programa:

      https://gitlab.com/BuiuDeJaraguaDoSul/calculadoracompletadebian/-/raw/master/CalculadoraCompleta.deb

      Calculadora de décimo terceiro salário:




      Download do programa:

      https://gitlab.com/BuiuDeJaraguaDoSul/calculadoradedecimoterceirosalariodebian/-/raw/master/CalculadoraDeDecimoTerceiroSalario.deb

      Criptografador:



      Download do programa:

      https://gitlab.com/BuiuDeJaraguaDoSul/criptografadordebian/-/raw/master/Criptografador.deb

      Gerador de Senha:



      Download do programa:
      https://gitlab.com/BuiuDeJaraguaDoSul/geradordesenhadebian/-/raw/master/GeradorDeSenha.deb

      Cronômetro:



      Download do programa:

      https://gitlab.com/BuiuDeJaraguaDoSul/cronometrodebian/-/raw/master/Cronometro.deb

      Visualizador de imagem:




      Download do programa:
      https://gitlab.com/BuiuDeJaraguaDoSul/visualizadordeimagemdebian/-/raw/master/VisualizadorDeImagem.deb

      Editor de Texto:



      Download do programa:
      https://gitlab.com/BuiuDeJaraguaDoSul/editordetextodebian/-/raw/master/EditorDeTexto.deb


      Calculadora Empresarial:



      Download do programa:
      https://gitlab.com/BuiuDeJaraguaDoSul/calculadoraempresarialdebian/-/raw/master/CalculadoraEmpresarial.deb
    • By 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
       
    • By 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
       
    • By 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
       
       
    • By 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
       
×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.