I'm trying to make a todo list with Rails, first I have made the List and it's specs, everything went okay, but then I've began to make it's items, but it simple don't save it's content, it stores a empty string, it don't work neither on the form or on the specs. When I try to save with the Rails console everything goes okay.
This is the message I receive from Rspec:
Creating todo items is successful with valid content
Failure/Error: expect(page).to have_content("Ruby")
expected to find text "Ruby" in ""
Above is the code for...
#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 %>
When it appear on the browser it displays only the list symbol but no content.
Sorry for too long
Aucun commentaire:
Enregistrer un commentaire