Tag: ruby on rails

在OS X Lion上与sqlite3 gem挣扎

我是Mac和Ruby on Rails的新手,我正在尝试设置我的环境。 我一直在研究这个教程,并试图在Mac OS X Lion上安装sqlite3 gem。 Xcode 4.2.1 git版本1.7.5.4 Ruby 1.9.3p0 gem -v结果为1.8.11 sqlite版本3.7.5 当我尝试运行gem install sqlite3或gem install sqlite3 — –with-sqlite3-dir=/usr/bin我得到下面的错误文本,有没有人有任何建议? Building native extensions. This could take a while… ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension. /Users/mikehking/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb –with-sqlite3-dir=/usr/bin checking for sqlite3.h… *** extconf.rb failed *** Could not create […]

Ruby on rails,阅读和显示csv文件不起作用?

我在Ruby on Rails中实现,我只想要一些容易做的事情,我只想读取一个csv文件,然后在视图中显示输出。 我有一些代码对我来说似乎很好,但我总是得到错误:无法将Tempfile转换为String这是我的控制器: def match file = params[:file] @original_filename = file.original_filename tmpfile = Tempfile.new(“redmine_project_importer”) if tmpfile tmpfile.write(file.read) tmpfile.close tmpfilename = File.basename(tmpfile.path) if !$tmpfiles $tmpfiles = Hash.new end $tmpfiles[tmpfilename] = tmpfile else flash[:error] = “Cannot save import file.” return end session[:importer_tmpfile] = tmpfilename sample_count = 5 i = 0 @samples = [] FasterCSV.open(file, “r”) do […]

在Rails中的Mailboxer收件箱中显示用户名

我在我的Rails应用程序中使用Mailboxer( https://github.com/ging/mailboxer )gem来处理用户之间的私人消息。 根据文档,我使用= render mailbox.inbox来显示登录用户的所有对话(消息)列表。 但是,该方法仅输出消息的主题。 我需要显示消息的发件人以及主题。 如何编辑此输出以显示发件人姓名? SQL表显示发件人名称未存储在会话表中,而是存储在notification_on_conversation_id(一对多)的通知表中。 我尝试使用但是我收到以下错误: NoMethodError in Conversations#index undefined method `notifications’ for nil:NilClass 我可以将哪些内容添加到会话控制器和视图中以显示会话的用户和主题? 谢谢! 对话控制器: class ConversationsController < ApplicationController before_filter :authenticate_user! helper_method :mailbox, :conversation def create recipient_emails = conversation_params(:recipients).split(',') recipients = User.where(email: recipient_emails).all conversation = current_user. send_message(recipients, *conversation_params(:body, :subject)).conversation redirect_to conversation end def reply current_user.reply_to_conversation(conversation, *message_params(:body, :subject)) redirect_to […]

Ruby on Rails:表关系搜索

我仍然无法搜索存储在单独表中的技术,其中技术表(technol)和Project表之间通过名为projecttechnol的表之间存在关系。 当我尝试使用技术(tech1)搜索项目时,这是我的日志。 Parameters: {“utf8″=>”✓”, “client”=>””, “industry”=>””, “role”=>””, “technols”=>{“id”=>[“”, “1”, “”]}, “business_div”=>””, “project_owner”=>””, “start_date_dd”=>””, “start_date_A”=>””, “start_date_B”=>””, “status”=>””, “keywords”=>””, “per_page”=>”10”} User Load (0.6ms) SELECT “users”.* FROM “users” WHERE “users”.”id” = 1 LIMIT 1 Technol Load (0.3ms) SELECT “technols”.* FROM “technols” Project Load (0.5ms) SELECT “projects”.* FROM “projects” ORDER BY client Project Load (0.6ms) SELECT “projects”.* FROM “projects” […]

无法在MacOSX 10.6上安装ruby 1.9.1

我似乎无法在我的Mac上安装Ruby。 这是我到目前为止采取的步骤: 从Ruby的网站下载软件包( http://www.ruby-lang.org/en/downloads/ ) 解压缩它运行{tar xzvf ruby​​-1.9.1-p376.tar.gz} 进入新的ruby文件夹,并使用{./configure}进行配置 这是错误发生的地方。 当我运行configure时,它给出了错误: /usr/local/include/fuse/fuse_common.h:32:2: error: #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! In file included from /usr/local/include/fuse/fuse.h:857, from :0: /usr/local/include/fuse/fuse_compat.h:69:24: error: sys/statfs.h: No such file or directory 因此,我无法制作包装或安装它。 我不知道出了什么问题。 任何帮助是极大的赞赏。 谢谢!

Rails f.select尝试禁用下拉列表进行更改

我正在尝试禁止在表单上更新下拉列表。 目前我的forms是这条线: @permissions_disabled}) %> 我的编辑控制器方法包含: @permissions_disabled = params[:id].to_i == current_user.id.to_i p @permissions_disabled 我可以在我的日志中清楚地看到1 @ permissions_disabled1为真,但是当我编辑表单时,我仍然可以在下拉列表中选择新值。 我在这做错了什么?

rake db:seed期间的问题,值没有正确设置

我想用app / db中的seeds.rb文件预填充我的表 但是在存储正确的数据时我遇到了问题。 在表用户中,我有一个名为active的列,数据类型为tinyint。 所以现在我想用seeds.rb int值存储 User.create([ { :id => 1, :firstname => ‘Felix’, :lastname => ‘Hohlwegler’, :active => 1}]) 但它不存储1.它总是在数据库中存储0。 也试过这个: User.create([ { :id => 1, :firstname => ‘Felix’, :lastname => ‘Hohlwegler’, :active => true}]) 同样的问题它在db中存储0。 什么出错了?

创建一个inheritance自Ruby中另一个类的类

我正在尝试创建一个名为Musician的类,它inheritance自我的类Person,然后添加一个instrument属性。 我知道我的音乐家课是错的,但我只是想知道Ruby中正确的格式是什么。 这是我的所有代码: class Person attr_reader :first_name, :last_name, :age def initialize (first_name, last_name, age) @first_name = first_name @last_name = last_name @age = age end end p = Person.new(“Earl”, “Rubens-Watts”, 2) p.first_name p.last_name p.age class Musician < Person attr_reader :instrument def initialize (instrument) @instrument = instrument end end m = Musician.new("George", "Harrison", 58, "guitar") m.first_name + […]

RedCloth安装期间的PATH问题

我正在尝试运行“bundle install”并尝试安装RedCloth。 但由于我的路径变量,在安装过程中似乎有问题。 当我尝试“gem install RedCloth”时,我有完全相同的错误。 我真的不知道我应该用我的PATH变量做什么。 http://img231.imageshack.us/img231/613/bad4f6afda58444fa77707b.png 我当前的PATH变量是“%APPDATA%\ Python \ Scripts; C:\ Program Files \ Google \ google_appengine \”

validation失败时渲染/重定向到新操作(rails)

我有一个表单,用户可以输入isbn,它会尝试查找书籍数据并保存。 当isbn查找validation失败时(例如,如果有人输入错误),我希望它重定向到另一种forms,如果isbn查找失败,用户可以手动输入数据(但如果其他validation如数字价格失败则不会)。 关于如何做到这一点的任何想法? 谢谢您的帮助!