Tag: ruby on rails 3.1

如何从rails中的给定列表创建选择框?

我从控制器传递一个列表 @distinct_grade_list = Student.uniq.pluck(:grade) 从模型学生创建不同的成绩列表 现在在我的视图页面中,如何将其显示为我正在使用的选择框 现在我需要保留A,B,C,D

如何在rails 3.1中为作用域/嵌套资源创建named_route_path?

这是我的路线: scope “:username” do resources :feedbacks end 当我做rake routes ,我明白了: feedbacks GET /:username/feedbacks(.:format) {:action=>”index”, :controller=>”feedbacks”} POST /:username/feedbacks(.:format) {:action=>”create”, :controller=>”feedbacks”} new_feedback GET /:username/feedbacks/new(.:format) {:action=>”new”, :controller=>”feedbacks”} edit_feedback GET /:username/feedbacks/:id/edit(.:format) {:action=>”edit”, :controller=>”feedbacks”} feedback GET /:username/feedbacks/:id(.:format) {:action=>”show”, :controller=>”feedbacks”} PUT /:username/feedbacks/:id(.:format) {:action=>”update”, :controller=>”feedbacks”} DELETE /:username/feedbacks/:id(.:format) {:action=>”destroy”, :controller=>”feedbacks”} 但是当我做feedbacks_url或feedbacks_path时,我得到一个像这样的路由错误: No route matches {:controller=>”feedbacks”, :format=>nil} 从日志文件: Rendered users/show.html.erb within layouts/application (18.3ms) Completed […]

新手:’rake -T’时出现错误信息

我正在为我的项目使用Ruby Enterprise Edition 。 当我通过运行命令rake -T检查所有rake任务时 ,我收到以下错误消息: You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this. 错误消息暗示我可以使用bundle exec来解决问题,但我不确定如何? 那么,如何摆脱这个错误信息? – – – – – – – – – – – – – – – 更多 – – – – – – – – – – ——– […]

多态关联和设置资产的默认值

新手问题。 我有以下型号: class Asset true #paperclip has_attached_file :asset, :hash_secret => “my-secret”, :url => “/images/:hash_:basename_:style.:extension”, :path => UPLOAD_PATH + “/:hash_:basename_:style.:extension”, :styles => { :medium => “300×300>”, :thumb => “75×75>” } end class Location :assetable, :dependent => :destroy end class MenuItem :assetable end 我的资产有一个叫做描述的属性。 如果assetable_type是“MenuItem”并且描述为nil,我希望描述是关联的menu_item的主体。 我该怎么办? 谢谢

如何在rails项目上导入ruby

我试图导入一个别人在1年前建立的项目,现在我的mac已经安装了以下所有包括: ruby, rails and mysql paperclip dragonfly authlogic sqlite3-ruby uuid rmagick thin or mongrel nokogiri rack-cache pony tiny_mce 可以任何人告诉如何导入项目,或任何在线链接可以帮助我吗?

样式表错误 – Ruby on Rails新手

我目前正在通过“使用Rails进行敏捷Web开发”来学习ruby,我遇到了一个我无法修复的错误。 到目前为止,我只做了一些基本的操作。 我创建了一个脚手架,其命令类似于: rails generate scaffold Product title:string description:text image_url:string price:decimal 然后我倾斜说: rake db:migrate 运行之后,我进入了db / seeds.db文件并使用以下数据填充了这个新创建的表: Product.delete_all Product.create(:title => ‘Web Design for Developers’, :description => %{ Web Design for Developers will show you how to make your web-based application look professionally designed. We’ll help you learn how to pick the right colors and fonts, […]

将Rails 3.0升级到3.1时,路由停止工作

我使用Ruby 1.8.7与Rails 3.1。 我的应用程序在Rails 3.0中运行良好,但是当我把它提升到Rails 3.1.4时,我所有的url帮助程序都破了! 在过去两天谷歌搜索疯子之后,我已经放弃了,现在是时候寻求帮助了。 我不相信问题是我的routes.rb文件,但在视图/帮助方面更多。 我的routes.rb中有以下内容: resources :sessions 在我的主页视图中,我有以下link_to,其中出错: 当我做rake路由时,我得到以下输出,所以路径存在: sessions GET /sessions(.:format) {:controller=>”sessions”, :action=>”index”} POST /sessions(.:format) {:controller=>”sessions”, :action=>”create”} new_session GET /sessions/new(.:format) {:controller=>”sessions”, :action=>”new”} edit_session GET /sessions/:id/edit(.:format) {:controller=>”sessions”, :action=>”edit”} session GET /sessions/:id(.:format) {:controller=>”sessions”, :action=>”show”} PUT /sessions/:id(.:format) {:controller=>”sessions”, :action=>”update”} DELETE /sessions/:id(.:format) {:controller=>”sessions”, :action=>”destroy”} 当我在浏览器中转到/ sessions / new时,页面再次加载,路由存在,但它在基于_path的url上出错: :post do -%> 我得到的错误如下: ActionView::Template::Error (undefined […]

Object.save在规范数据validation中失败

以下是客户控制器中创建的失败规范代码: describe CustomersController do before(:each) do #the following recognizes that there is a before filter without execution of it. controller.should_receive(:require_signin) controller.should_receive(:require_employee) end render_views describe “‘create’ successful” do before(:each) do category = Factory(:category) sales = Factory(:user) @customer = Factory.attributes_for(:customer, :category1_id => category.id, :sales_id => sales.id) session[:sales] = true session[:user_id] = sales.id session[:user_name] = sales.name session[:page_step] = […]

ActiveAdmin:按关联排序(belongs_to)

我有一个索引管理员视图,我正在显示一个关联的模型City 。 我希望能够按城市名称排序,但是当我单击列标题进行排序时,我收到以下错误: ActiveRecord::StatementInvalid in Admin/deals#index SQLite3::SQLException: no such column: cities.name: SELECT “deals”.* FROM “deals” ORDER BY cities.name desc LIMIT 30 OFFSET 0 索引视图 ActiveAdmin.register Deal do index do column :id column :city end … end 模型 class Deal < ActiveRecord::Base belongs_to :city end 我怎么能按城市排序?

在创建日期之前列出对象

对不起业余的问题,但我还是很新的铁路。 我目前有一个创建工作的应用程序,我想在它们创建日期之下显示作业,就像它们在Dribble上一样 目前显示我以下的工作: are looking for a 我确信我需要创建一种类型的循环来使这项工作,但我不确定如何合并它,以便日期只在作业的顶部显示一次,然后显示在该日期创建的所有作业? 任何帮助将非常感激! 谢谢