lundi 13 avril 2015

Heroku "Something Went Wrong" when trying to create a new form

I am trying to make a form that will create a new 'room'. However, when I push it to Heroku I am getting this error: 'We're sorry, but something went wrong.' I am using rails 4.1 and ruby 2.1.1. I am also using Heroku.


If it helps, I am kind of new to rails and am trying to port what I learned here to my new 'rooms' type.


This is my view/model/controller:


view: (app/views/rooms/index.html.erb)



<% if current_user %>
<h1>Create Room</h1>
<div class="Sign_Form">
<%= form_for(:room, :url => {:controller => 'rooms', :action => 'create'}) do |f| %>
<p> Created By:</br> <%= f.text_field :created_by%> </p>
<p> Name:</br> <%= f.text_field :name%> </p>
<p> Description:</br> <%= f.text_field :description%> </p>
<%= f.submit :Createroom %>
<% end %>
<% if @room.errors.any? %>
<ul class="Createroom_Errors">
<% for message_error in @room.errors.full_messages %>
<li>* <%= message_error %></li>
<% end %>
</ul>
<% end %>
</div>

<h1>All Rooms</h1>
<% if @rooms.nil? %>
Rooms is nil
<% else %>
<% @rooms.each do |room| %>
<%= room.name %>
<% end %>
<% end %>
<% else %>
<%= render 'welcome' %>
<% end %>


Model: (app/model/room.rb)



class Room < ActiveRecord::Base
class << self
end
end


Controller: (app/controllers/rooms_controller.rb)



class RoomsController < ApplicationController
def index
@rooms = Room.all
end

def new
@room = Room.new
end

def create
@room = Room.new(params[:room])
if @room.save
flash[:notice] = "Room has been created!"
flash[:color] = "valid"
else
flash[:notice] = "Room has not been created!"
flash[:color] = "invalid"
end
render new
end
end


Any help would be highly appreciated. Thanks ahead of time.


EDIT: When I run it on localhost it says: undefined method `errors' for nil:NilClass.


Aucun commentaire:

Enregistrer un commentaire