标签: ruby-on-rails-4

rails 4资产管道供应商资产图像未进行预编译

我使用rails 4和ruby 1.9.3作为我的应用程序和fancybox2-railsgem,但是资产管道存在一个普遍的问题.如果我运行rake task了预编译,那么一切都只是在出细腻的图像vendor/assets/images../gems/ruby-1.9.3-p327/gems/fancybox2-rails-0.2.1/vendor/assets/images.来自这两个文件夹的图像没有被预编译,最终我遇到了与不存在的图像的死链接的问题.有什么建议?

asset-pipeline ruby-on-rails-4

60
推荐指数
3
解决办法
3万
查看次数

has_many,belongs_to关系在活动记录迁移rails 4中

我创建了一个User模型,后来创建了一个Task模型.创作时我没有提到它们之间的任何关系.

我理解User has_many Tasks和a Task belongs_to User.我需要通过迁移在它们之间建立这种关系.

我的问题是,建立这种关系的迁移生成命令是什么?

任何帮助将受到高度赞赏.

ruby-on-rails rails-migrations ruby-on-rails-4 rails-activerecord

59
推荐指数
4
解决办法
6万
查看次数

如何在重定向时显示Rails闪存通知?

我在Rails控制器中有以下代码:

flash.now[:notice] = 'Successfully checked in'
redirect_to check_in_path
Run Code Online (Sandbox Code Playgroud)

然后在/ check_in视图中:

<p id="notice"><%= notice %></p>
Run Code Online (Sandbox Code Playgroud)

但是,通知没有显示出来.如果我不在控制器中重定向,则工作完美:

flash.now[:notice] = 'Successfully checked in'
render action: 'check_in'
Run Code Online (Sandbox Code Playgroud)

我需要重定向...而不仅仅是对该动作的渲染.重定向后可以有闪光通知吗?

ruby-on-rails rails-flash ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-4

58
推荐指数
5
解决办法
7万
查看次数

为什么我要求运行'rake db:migrate RAILS_ENV = test'?

在Rails 4.0.0.rc1,Ruby 2.0.0上,运行迁移后,当我尝试运行测试时,我看到以下错误rspec:

/Users/peeja/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:376:in`check_pending! ':正在等待迁移; 运行'rake db:migrate RAILS_ENV = test'来解决此问题.(ActiveRecord的:: PendingMigrationError)

这似乎不对.没有人迁移他们的测试数据库,是吗?他们db:test:prepare,这是公平的 - 我忘了做.所以我再次运行rake db:test:prepare并运行我的rspec命令......并看到同样的错误.

如果我真的rake db:migrate RAILS_ENV=test,错误确实消失了.

这是怎么回事?这是Rails 4中的新功能吗?

ruby-on-rails rails-migrations ruby-on-rails-4

58
推荐指数
4
解决办法
9万
查看次数

Heroku上的"bin/rails:没有这样的文件或目录"w/Ruby 2&Rails 4

在遵循Michael Hartl的Ruby on Rails教程的Rails 4 Beta版本时,我的应用程序无法在Heroku上启动,但在本地运行良好.检查显示以下错误:bundle exec rails serverheroku logs -t

$ heroku[web.1]: State changed from crashed to starting
$ heroku[web.1]: Starting process with command `bin/rails server 
-p 33847 -e $RAILS_ENV`
$ app[web.1]: bash: bin/rails: No such file or directory
$ heroku[web.1]: Process exited with status 127
$ heroku[web.1]: State changed from starting to crashed
$ heroku[web.1]: Error R99 (Platform error) -> Failed to launch the 
dyno within 10 seconds
$ heroku[web.1]: Stopping process with …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails heroku ruby-2.0 ruby-on-rails-4

57
推荐指数
3
解决办法
3万
查看次数

使用simple_form输入的默认值

我试图做输入的默认值

工作正常:

<%= f.input_field :quantity, default: '1' %> 
Run Code Online (Sandbox Code Playgroud)

但我需要f.input而不是f.input_field

<%= f.input :quantity %> 
Run Code Online (Sandbox Code Playgroud)


怎么解决这个?有没有像f.input_field那样的选择 - :默认?还是有其他有价值的解决方案?

ruby-on-rails erb simple-form ruby-on-rails-4

57
推荐指数
2
解决办法
4万
查看次数

Ruby on rails 4 app在iframe中不起作用

如何通过iframe将我的rails应用程序嵌入到另一个网站?

它适用于RoR 3,但不适用于RoR 4:

<iframe src="http://myrailsapp.com/" width="100%" height="50" id="rails_iframe">error!</iframe>
Run Code Online (Sandbox Code Playgroud)

我试图在我的控制器中使用verify_authenticity_tokenprotect_from_forgery选项...似乎它是另一回事(但我不确定).

UPD.示例:http: //jsfiddle.net/zP329/

iframe ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

56
推荐指数
2
解决办法
3万
查看次数

尝试创建模型时,"rails generate"命令会挂起

我是rails的新手,今天早上决定抛弃我的整个数据库设计/模型并重新开始.作为一个菜鸟,我肯定做错了.

我删除了所有文件db/migrate/并删除了表格.当我试图生成第一个新的模型类时,rails就挂了.在我赶上^ C然后尝试别的东西之前,在杂草中关闭了10分钟.

这一次,我再次删除了表格,将整个项目移动到project.bad并运行rails new重新开始.再次,在使用旧名称生成新项目之后,它挂起了rails generate命令(我使用相同的项目名称).

无奈之下,我尝试在同一根中创建一个新项目,但使用另一个名称.找到了!这就像一个冠军,创建控制器和模型类,但我完全无法使用原始项目名称,原始项目或任何新创建的项目生成任何内容.为了让这个工作再次起作用,我错过了什么?我不介意在这一点完全失去,但我希望能够再次使用原始项目名称!

这是log/development.log的样子:

   (255.5ms)  CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
   (337.7ms)  CREATE UNIQUE INDEX `unique_schema_migrations`  ON `schema_migrations` (`version`) 
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
   (0.2ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations`
Run Code Online (Sandbox Code Playgroud)

知道在最后一次SELECT之后应该发生什么吗?

ruby-on-rails ruby-on-rails-4

56
推荐指数
4
解决办法
1万
查看次数

rails 4:404,500的自定义错误页面以及来自哪里的默认500错误消息?

目前正在制作中获取此文字:

500 Internal Server Error
If you are the administrator of this website, then please read this web application's     
log file and/or the web server's log file to find out what went wrong.
Run Code Online (Sandbox Code Playgroud)

该页面中没有任何HTML.

这段代码在哪里?我没有公开/ 500.html或这方面的任何事情.

在我的路线中,我有:

  get "/404", :to => "errors#error_404"
  get "/422", :to => "errors#error_404"
  get "/500", :to => "errors#error_500"
  get "/505", :to => "errors#error_505"
Run Code Online (Sandbox Code Playgroud)

ErrorsController:

class ErrorsController < ApplicationController

  def sub_layout
    "left"
  end

  def error_404
    render :status => 404, :formats => [:html], :layout => "white", …
Run Code Online (Sandbox Code Playgroud)

error-handling ruby-on-rails-4

54
推荐指数
3
解决办法
6万
查看次数

在Rails 4中使用logger

我正在开发一个Rails 4项目,当我打电话给Rails.logger.debug "test"我尝试在线搜索时,我似乎无法在我的开发日志中显示任何内容,但我觉得我没有取得多大进展.我如何设置记录器并告诉它在我的开发日志文件中写入?

任何帮助将不胜感激.

logging ruby-on-rails-4

53
推荐指数
2
解决办法
8万
查看次数