我试图将mongo_mapper的简单rails 3.2.3应用程序推送到cloudfoundry,但我得到504网关超时。该应用程序在localhost上正常运行。我在下面提供了其他信息。请您帮我解决这个问题?
创建并推送我输入的应用程序:
rails new myapp -skip-active-record
scaffold massage content:string --skip-migration --orm mongo_mapper
bundle update
bundle install
bundle package
vmc push myapp --runtime ruby19
这是Gemfile:
Source 'http://rubygems.org'
gem rails', '3.2.3
gem mongo_mapper
gem bson_ext
end
这是控制器:
class MessagesController < ApplicationController
def index
@messages = Message.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @messages }
end
end
def show
@message = Message.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @message }
end
end
def new
@message = Message.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @message }
end
end
def edit
@message = Message.find(params[:id])
end
def create
@message = Message.new(params[:message])
respond_to do |format|
if @message.save
format.html { redirect_to @message, notice: 'Message was successfully created.' }
format.json { render json: @message, status: :created, location: @message }
else
format.html { render action: "new" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
end
def update
@message = Message.find(params[:id])
respond_to do |format|
if @message.update_attributes(params[:message])
format.html { redirect_to @message, notice: 'Message was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
end
def destroy
@message = Message.find(params[:id])
@message.destroy
respond_to do |format|
format.html { redirect_to messages_url }
format.json { head :no_content }
end
end
end
这是模型:
class Message
include MongoMapper::Document
key :content, String
end
这是索引视图
<h1>Listing messages</h1>
<table>
<tr>
<th>Content</th>
</tr>
<% @messages.each do |message| %>
<tr>
<td><%= message.content %></td>
<td><%= link_to 'Show', message %></td>
<td><%= link_to 'Edit', edit_message_path(message) %></td>
<td><%= link_to 'Destroy', message, :confirm => 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Message', new_message_path %>
这是config / locales / mongo.yml
defaults: &defaults
host: 127.0.0.1
port: 27017
development:
<<: *defaults
database: proj815_development
test:
<<: *defaults
database: proj815_test
# set these environment variables on your prod server
production:
host: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-1.8'].first['credentials']['hostname'] rescue 'localhost'%>
port: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-1.8'].first['credentials']['port'] rescue '27017'%>
database: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-1.8'].first['credentials']['db'] rescue 'proj815' %>
username: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-1.8'].first['credentials']['username'] rescue ''%>
password: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-1.8'].first['credentials']['password'] rescue ''%>
答案 0 :(得分:2)
通常这是因为您的应用程序太大而无法上传,如果您可以减小应用程序的大小,那么您应该没问题。