Commit 6f97e13
Changed files (3)
app
controllers
views
items
spec
controllers
app/controllers/items_controller.rb
@@ -3,6 +3,7 @@ class ItemsController < ApplicationController
def index
@items = current_user.items
+ @item = Item.new
end
def show
@@ -10,7 +11,7 @@ class ItemsController < ApplicationController
end
def new
- @item = Item.new
+ @item = params[:item].present? ? Item.new(secure_params) : Item.new
end
def edit
app/views/items/index.html.erb
@@ -1,12 +1,29 @@
<div class="row">
<!-- Side Bar -->
<div class="large-4 small-12 columns">
- <img src="http://placehold.it/500x500&text=Logo">
-
<div class="hide-for-small panel">
<h3>Header</h3>
- <h5 class="subheader">Risus ligula, aliquam nec fermentum vitae, sollicitudin eget urna. Donec dignissim nibh fermentum odio ornare sagittis.
- </h5>
+ <h5 class="subheader">Risus ligula, aliquam nec fermentum vitae, sollicitudin eget urna. Donec dignissim nibh fermentum odio ornare sagittis.</h5>
+<%= form_for(@item, url: new_item_path, method: :get) do |f| %>
+ <% if @item.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2>
+ <ul>
+ <% @item.errors.full_messages.each do |message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br>
+ <%= f.text_field :name %>
+ </div>
+ <div class="actions">
+ <%= f.submit class: 'btn' %>
+ </div>
+<% end %>
</div>
<a href="#">
spec/controllers/items_controller_spec.rb
@@ -40,6 +40,11 @@ RSpec.describe ItemsController, type: :controller do
get :new
expect(assigns(:item)).to_not be_nil
end
+
+ it "loads up the params for a new item" do
+ get :new, item: { name: 'hammer' }
+ expect(assigns(:item).name).to eql('hammer')
+ end
end
describe "#edit" do