尝试创建新表单时,Heroku“Something Went Wrong”

时间:2015-04-13 23:45:08

标签: ruby-on-rails ruby forms ruby-on-rails-4 heroku

我正在尝试创建一个可以创建新“房间”的表单。然而,当我把它推到Heroku时,我收到了这个错误:'我们很抱歉,但出了点问题。'我使用rails 4.1和ruby 2.1.1。我也在使用Heroku。

如果它有帮助,我对rails有点新意,并试图将我学到的here移植到我的新“房间”类型。

这是我的观点/型号/控制器:

查看(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 %>

型号(app / model / room.rb)

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

控制器:(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

任何帮助都将受到高度赞赏。提前谢谢。

编辑:当我在localhost上运行时,它说:nil的未定义方法`errors':NilClass。

0 个答案:

没有答案