1

В настоящее время я работаю над приложением для рецептов, используя рубины на рельсах. Когда я хочу, чтобы создать новый рецепт Это говоритПочему я получаю NoMethodError в Ruby?

неопределенный метод `название»

для

= f.input :title, input_html: { class: 'form-control' } 

Это мой form.html.haml

= simple_form_for @recipe, html: { multipart: true } do |f| 
    - if @recipe.errors.any? 
     #errors 
      %p 
       = @recipe.errors.count 
       Prevented this recipe from saving 
      %ul 
       - @recipe.errors.full_messages.each do |msg| 
        %li= msg 
    .panel-body 
     = f.input :title, input_html: { class: 'form-control' } 
     = f.input :description, input_html: { class: 'form-control' } 

    = f.button :submit, class: "btn btn-primary" 

И это мое r ecipes_controller.rb

class RecipesController < ApplicationController 
before_action :find_recipe, only: [:show, :edit, :update, :destroy] 

def index 
end 

def show 
end 

def new 
    @recipe = Recipe.new 
end 

def create 
    @recipe = Recipe.new(recipe_params) 

    if @recipe.save 
     redirect_to @recipe, notice: "Toll! Neues Rezept erfolgreich erstellt." 
    else 
     render 'new' 
    end 
end 

private 

def recipe_params 
    params.require(:recipe).permit(:title, :description) 
end 

def find_recipe 
    @recipe = Recipe.find(params[:id]) 
end 

конец

+0

Можете ли вы опубликовать либо схему БД для таблицы 'recipes', либо файл миграции, который создал таблицу' recipes' (и любые последующие изменения)? – ArtOfCode

+1

похоже, что у вас нет столбца 'title' в таблице' recipes' на вашей БД –

ответ

1
  1. Вы должны вынести форму в 'новом' зрения
  2. Вы должны иметь столбец 'название' в вашей БД

Покажите нам что 'debug @recipe' печатает, есть ли атрибут title?

 Смежные вопросы

  • Нет связанных вопросов^_^