2016-03-25 39 views
1

ile kaydetme konusunda sorunlar yaşıyorum Rails ile bir yapılacaklar listesi yapmaya çalışıyorum, önce Listeyi yaptım ve özellikleri var, her şey yolunda gitti, ama sonra bu işi yapmaya başladım, ama Basit bir içeriği saklamayın, boş bir dize depolar, formda veya teknik özelliklerde işe yaramıyor. Rails konsoluyla kurtarmaya çalıştığımda her şey yolunda gider.Ruby on Rails

Creating todo items is successful with valid content 
Failure/Error: expect(page).to have_content("Ruby") 
    expected to find text "Ruby" in "" 

Üstü kodu için ...

#todo_item_controller.rb 

class TodoItemsController < ApplicationController 
    def index 
    @todo_list = TodoList.find{ params[:todo_list_id] } 
    end 

    def new 
    @todo_list = TodoList.find{ params[:todo_list_id] } 
    @todo_item = @todo_list.todo_items.new 
    end 

    def create 
    @todo_list = TodoList.find(params[:todo_list_id]) 
    @todo_item = @todo_list.todo_items.new(todo_item_params) 
    if @todo_list.save 
     flash[:success] = "Added todo list item." 
     redirect_to todo_list_todo_items_path 
    else 
     flash[:error] = "Something went wrong" 
     render action: :new 
    end 
    end 

    private 
    def todo_item_params 
     params[:todo_item].permit{:content} 
    end 
end 

#index.html.erb 

<h1><%= @todo_list.title %></h1> 

<ul class="todo_items"> 
    <% @todo_list.todo_items.each do |todo_item| %> 
    <li><%= todo_item.content %></li> 
    <% end %> 
</ul> 
<p> 
    <%= link_to "New Todo item", new_todo_list_todo_item_path %> 
</p> 

#new.html.erb 

<%= form_for [@todo_list, @todo_item] do |form| %> 
    <%= form.label :content %> 
    <%= form.text_field :content %> 

    <%= form.submit "Save" %> 
<% end %> 

tarayıcıda göründüğünde yalnızca liste sembolü ama hiçbir içeriği görüntüler geçerli:

Bu

ben RSpec aldığımız mesajdır . Çok uzun

cevap

2

Değişim için

Maalesef senin

def todo_item_params 
    params.require(:todo_item).permit(:content) 
end 

Raylar strong parameters bir göz atın todo_item_parems

için.

+0

Çalıştı! Çok teşekkürler! – joaomarcuslf