每次我更改控制器或模型中的任何内容时,我都必须重新启动服务器才能使其生效.但情况并非总是如此,以前它曾经正常工作,当我改变了什么,但我不知道现在发生什么事 ?
我的Rails版本是3.2.11
在我的开发环境文件中,我设置了config.cache_classes = false.
请帮忙..
我的development.rb文件如下
Testapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# …Run Code Online (Sandbox Code Playgroud) 我正在创建一个示例项目,但是当我尝试创建一个新帖子时收到错误"未定义的方法为nil类创建"
我的代码如下.
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_one :post, dependent: :destroy
end
Run Code Online (Sandbox Code Playgroud)
post.rb
class Post < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
posts_controller.rb
class PostsController < ApplicationController
def create
@user = current_user
if @user.post.blank?
@post = @user.post.create(params[:post].permit(:title, :text))
end
redirect_to user_root_path
end
end
Run Code Online (Sandbox Code Playgroud)
new.html.erb
<%= form_for([current_user, current_user.build_post]) do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %> …Run Code Online (Sandbox Code Playgroud) 我想使用 Ruby 从给定的数组中生成最大的数字。
示例 1
## Input
my_array = %w{8 40 9}
## Expected Output
"9840"
Run Code Online (Sandbox Code Playgroud)
示例 2
## Input
my_array = %w{9 8 40 9}
## Expected Output
"99840"
Run Code Online (Sandbox Code Playgroud)