Tag: ruby on rails 3.1

Rails 3.1自定义控制器和视图w /默认

背景: 我正在构建一个允许用户创建自己的网站的应用程序(例如,mywebsite.alexlod.com) 每个网站所有者都隶属于我,所以我相信他们会编写自己的rails代码 每个网站都应该有默认的控制器和视图,除非其中一个所有者创建自己的 以下是我设想控制器的工作方式: 我认为app/controllers/将是默认值,但是当在顶级目录中指定文件时,该文件将优先于默认值。 让我举个例子。 假设我的一个网站所有者(foo.alexlod.com)想要调整app/controllers/photos_controller.rb 。 他们应该能够创建foo/controllers/photos_controller.rb ,从而使用他们的控制器而不是默认控制器。 我认为这里的正确方法与路由和加载路径有关,但我是Rails和Ruby的新手,可以使用一些指导。 至于观点,我希望他们的工作方式大致相同。 在/views/定义视图或部分/views/ ,将使用该视图而不是app/views/中的默认app/views/ 。 我意识到我的计划违反了默认的rails目录结构。 但是这种方法必须比每个控制器操作中的替代 – case语句更简单。 除非有更好的选择吗?

Heroku运行rake db:迁移错误,“没有这样的文件加载 – bundler / setup”

我正在尝试做一个“heroku run rake db:migrate”,并收到此错误: es-MacBook-Pro:project e$ heroku run rake db:migrate Running rake db:migrate attached to terminal… up, run.1 (in /app) rake aborted! no such file to load — bundler/setup :29:in `require’ :29:in `require’ /app/config/boot.rb:6:in `’ :29:in `require’ :29:in `require’ /app/config/application.rb:1:in `’ :29:in `require’ :29:in `require’ /app/Rakefile:5:in `’ /usr/local/lib/ruby/1.9.1/rake.rb:2373:in `load’ /usr/local/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile’ /usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile’ […]

rails 3.1 app中的CKEditor文本区域为空

我试图将一个ckeditor嵌入到一个表单中,它只是空白。 文本区域只是一个空白区域,我希望找到一个html编辑器窗口。 我有一个模型,我希望“描述”字段是html文本。 我认为使用ckeditor编辑它会很方便。 我无法弄清楚为什么文本字段编辑器没有显示。 我有一个rails 3.1应用程序,我正在使用ckeditor gem(版本3.6.2)。 我已经下载了ckeditor并把它放在我的assets / javascripts文件夹中。 在我的application.html.erb文件中,我有这一行: 在我看来,我有一些像这样的代码: ‘Full’, :width => 800, :height => 400 %> 这会生成如下的html: // 这一切看起来都应该有效,但事实并非如此。 我错过了什么?

为什么我对资产管道的请求“没有路由匹配”?

我正在努力升级应用程序以使用Rails 3.1,我正在尝试使用资产管道。 作为测试,我已将foobar.js添加到app/assets/javascripts 。 安装程序 在application.rb ,我添加了config.assets.enabled = true 。 继续本指南 ,我认为这就是我所要做的。 检查出来 如果我加载控制台并检查Rails.application.config.assets.paths ,我确实在加载路径中看到了app/assets/javascripts 。 此外,如果我检查MyAppName::Application.assets ,我会得到一个具有相同路径的Sprockets::Environment对象。 这对我来说都很好看。 试着用它 在视图中,我使用的是javascript_include_tag(‘foobar’) 。 这将输出以下HTML: 错误 在该链接后出现错误: No route matches [GET] “/javascripts/foobar.js” 我缺少一个设置吗? 其他详情 我目前正在使用: ruby1.9.2-P290 轨,3.1.0.rc6 sprockets-2.0.0.beta.14(Rails需要)

在我的注册视图页面中我的collection_select有什么问题

我是rails的新手, 我正在使用ryan batesvideo教程的设计,而且,我一度陷入困境 我创建了用户,角色关系 在注册页面中,我需要为现有角色提供选择选项组, 在我正在写的注册视图页面 我没有准确理解collection_select方法,请帮助我可能做错了 我的模型1:user.rb class User < ActiveRecord::Base has_and_belongs_to_many :roles devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me , :roles has_and_belongs_to_many :roles def role?(role) return !!self.roles.find_by_name(role.to_s.camelize) end end 我的模型2:role.rb class Role < ActiveRecord::Base attr_accessible :name has_and_belongs_to_many :users end 我的用户迁移文件 class DeviseCreateUsers false, :default => “” t.string :encrypted_password, […]

如何在rails 3.1中为多对多关系保存联合表中的2个id

有两种型号。 一个是rfq,另一个是标准。 它像是: class Rfq << ActiveRecord::Base has_and_belongs_to_many :standards end class Standard << ActiveRecord::Base has_and_belongs_to_many :rfqs end 表rfqs_standards已创建。 我的问题是在创建rfq时,如何自动保存表rfqs_standards中的rfq_id和standard_id。 想在rfq模型中添加accepts_nested_attributes_for :standard 。 但是,由于没有为这种多对多关系保存的真实属性(但只是一对id),这似乎不是正确的方法。 rfq和standard都在routes.rb中声明为resources :rfqs和resources :standards. 该过程是在创建rfq时,将通过下拉列表选择标准。 然后保存rfq,同时创建联合表中的新条目。 创建新标准时,无需在联合表中创建条目。 有关在关联表中保存id的建议吗? 谢谢。

尝试使用Best In Place更新索引中的记录

我试图使用单独的jQuery或就地编辑器“Best In Place”来更新索引中的记录。 没有获得复选框并且在行上丢失格式。 我使用这个rails cast作为指南但是当我使用Ryan使用的复选框上的语法时,我得到一个错误说: 更新:Ruby 1.8.7 语法错误,意外’:’,期待’)’ 码 – application.js中: //= require jquery //= require jquery_ujs //= require_tree . //= require jquery.tablednd_0_5.js //= require jquery.tablesorter.js //= require jquery.purr //= require best_in_place 评论,crb_agenda和pre_release_agenda咖啡脚本: jQuery -> $(‘.best_in_place’).best_in_place() comments_controller.rb#更新 def update @comment = Comment.find(params[:id]) respond_to do |format| if @comment.update_attributes(params[:comment]) Comment.add_comment_to_jira_ticket(“MCTEST-293”,@comment.user_comments) format.html { redirect_to @comment, :notice => […]

rails 3中嵌套模型的部分forms

我有两个模型页面和作者,这里是模型页面的代码: 编辑-1 现在我的模特如下: class Page true belongs_to :author end 作者模型: class Author < ActiveRecord::Base has_many :pages end 我的表格如下: prohibited this post from being saved: 和控制器: class PagesController “The data has been saved!” else render “new” end end def edit @page = Page.find(params[:id]) end def update @page = Page.find(params[:id]) if @page.update_attributes(params[:page]) redirect_to pages_path, :notice => “Your […]

pdfkit的image和print_media_type无法在rails 4.0.2上运行

我使用pdfkit创建了一个pdf.Pdf已创建。 但是我的pdf上没有显示图像,print_media_type也无法正常工作。 我使用的是rails 4.0.2和ruby 2.0.0。 有谁可以帮我解决这个问题? 我在这里附上细节。 谢谢。 gem文件: gem ‘pdfkit’,’0.5.2′ gem ‘wkhtmltopdf-binary’,’0.9.9.1′ gem ‘wkhtmltopdf-heroku’,’1.0.0′ application.css: @media print { body { text-align: justify; font-size:566px; background-color: red; } } application.rb中: require “pdfkit” config.middleware.use PDFKit::Middleware, :print_media_type => true config / initializers / pdfkit.rb: PDFKit.configure do |config| config.wkhtmltopdf = ‘C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe’ config.default_options = { :page_size => ‘A4’, :page_height […]

任何新的TextMate资源?

所以,我刚刚安装了OSX Lion并且一直试图在它上面设置TextMate(第一次使用TextMate)。 我已经找到了关于安装捆绑包的所有这些链接,但我似乎无法将它们中的任何一个加载到程序中。 例如,在几乎所有TextMate包中,从github提取代码后,始终列出此命令: osascript -e ‘tell app “TextMate” to reload bundles’ 这样做会给我这样的回应: 2011-09-16 17:32:55.276 osascript[19941:707] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper osascript: OpenScripting.framework – scripting addition “/Library/ScriptingAdditions/Adobe Unit Types.osax” declares […]