小编gug*_*son的帖子

Rails 3.1 - 更改默认的脚手架视图和模板

我正在使用带有Zune Foundation模板和haml的rails 3.1.我试图改变默认的脚手架视图模板以使用我想要的css的方法,所以我得到了所有脚手架的一致外观,而无需手动更改视图.我也使用simple_form.

由于我不想编写自己的生成器,是否有一些简单和/或推荐的方法来处理它?

约翰

haml views scaffolding css3 ruby-on-rails-3

13
推荐指数
1
解决办法
4878
查看次数

使用Heroku db获取SQLite错误:当我使用PostgreSQL作为开发数据库时推送

我在将数据从我的开发数据库推送到Heroku时遇到了问题.我决定切换到PostgreSQL作为我的开发数据库并更新了database.yml并从gemfiles中删除了sqlite gem.

该应用程序运行良好对PostgreSQL但当我尝试运行命令时:

heroku db:push
Run Code Online (Sandbox Code Playgroud)

我得到一个令人费解的SQLite错误,因为我的项目中没有对sqlite的引用:

 !    Taps Load Error: cannot load such file -- sqlite3
 !    You may need to install or update the taps gem to use db commands.
 !    On most systems this will be:
 !    
 !    sudo gem install taps
Run Code Online (Sandbox Code Playgroud)

这是我的database.yml文件:

development:
  adapter: postgresql
  encoding: unicode
  database: xxxx
  pool: 5
  timeout: 5000
  username: xxxx
  password: xxxx

test:
  adapter: postgresql
  encoding: unicode
  database: test
  pool: 5
  timeout: 5000
  username: xx
  password: xx

production:
  adapter: postgresql
  encoding: unicode …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails heroku taps

12
推荐指数
2
解决办法
3163
查看次数

连接到Mac上的SQL Server的FreeTDS问题(来自服务器的意外EOF)

我已经设置FreeTDS连接到SQL Server数据库.当我尝试在Mac(Lion)上的终端中打开TSQL时出现此错误:

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20017 (severity 9):
    Unexpected EOF from the server
    OS error 36, "Operation now in progress"
Error 20002 (severity 9):
    Adaptive Server connection failed
There was a problem connecting to the server
Run Code Online (Sandbox Code Playgroud)

有没有人知道可能导致这种情况的原因?

sql-server freetds ruby-on-rails-3

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

在视图中使用fields_for的Rails 3不起作用

我正在尝试使用fields_for以rails形式实现主细节.

我有一个名为Recipe的模型:

class Recipe < ActiveRecord::Base
  validates :name,  :presence => true
  validates :directions, :presence => true

  has_many :recipe_ingredients 
end
Run Code Online (Sandbox Code Playgroud)

和一个名为RecipeIngredient的模型:

class RecipeIngredient < ActiveRecord::Base
  belongs_to :recipe
  #belongs_to :ingredient
end
Run Code Online (Sandbox Code Playgroud)

在新的控制器中,我用三个空记录填充成分,如下所示:

def new
    @recipe = Recipe.new
    3.times {@recipe.recipe_ingredients.build}
    # @ingredients = RecipeIngredient.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @recipe }
    end
  end
Run Code Online (Sandbox Code Playgroud)

我想在视图中做的是输出食谱字段(工作正常)和配方成分的三个字段.在视图的顶部我有这个:

<%= form_for :rec do |f| %>
Run Code Online (Sandbox Code Playgroud)

然后我列出正确显示的配方字段,如:

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
Run Code Online (Sandbox Code Playgroud)

然后我尝试显示成分行,但代码似乎永远不会进入fields_for部分:

第一次尝试:

<% for …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

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

Rails控制台 - 向上箭头不适用于最后一个命令

我在Rails 3中使用rails控制台时遇到小问题.

我在终端使用Mac和zsh.当我运行rails控制台时,我提示:

ruby-head :001 >
Run Code Online (Sandbox Code Playgroud)

当我尝试使用向上箭头重复上一个命令时,我收到一个错误声音并且没有显示该命令.另外要使用tab作为自动完成,我必须按Tab键两次.

另一个问题是,在我提供rails console命令之前大约需要10秒钟,直到显示控制台.这是正常的吗?

此致,约翰

ruby-on-rails-3

1
推荐指数
1
解决办法
1274
查看次数

在Rails中从模型中获取图像的路径

我正在使用一个名为Gmaps4Rails的模块的地图应用程序.使用这个gem我从我的模型中定义了图像的路径,并且可以根据我正在使用的图像的某些数据来获取它.它在开发环境中工作正常,但由于无法找到图像文件夹而导致生产中断.这就是代码在模型中的样子:

  def gmaps4rails_marker_picture

    {
    "picture" => "/images/oilpumpjack.png",
    "width" => "32",
    "height" => "32"
    }
  end
Run Code Online (Sandbox Code Playgroud)

有没有简单的方法从模型中获取正确的路径(我不想对其进行硬编码)?

此致,约翰

model ruby-on-rails-3

1
推荐指数
1
解决办法
3656
查看次数

在控制器中将行拆分为多行时,Rails 3语法错误在开发中

当我在我的本地文件上开发我的项目时,我在代码中使用了这行正常工作:

@json = Location.qty_of_deliv_from(params[:from_rc])
  .qty_of_deliv_to(params[:to_rc])
Run Code Online (Sandbox Code Playgroud)

当我与乘客进行deployd时,我在这一行上遇到语法错误,如果我在同一行中包含所有代码,那么就会失败:

@json = Location.qty_of_deliv_from(params[:from_rc]).qty_of_deliv_to(params[:to_rc])
Run Code Online (Sandbox Code Playgroud)

这是一个已知的问题?

ruby deployment passenger ruby-on-rails-3

1
推荐指数
1
解决办法
408
查看次数