- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试在我的 Rails 应用程序中使用回形针插件来上传帖子的图像。我在 Ubuntu 10.04 操作系统上使用 Rails 2.0.2 和 ruby 1.8.7 用于项目特定目的。
我指的是以下教程:-
我通过以下方式对回形针插件进行了 git 克隆:- https://github.com/thoughtbot/paperclip ,但是像 ruby script/generate paperclip group_post photo
这样的命令没有为它生成迁移。然后,我通过 ruby script/generate 创建了一个相同的迁移,并上传了我的表 group_posts
的适当列。
然后我尝试安装 gem,因为我使用的是 activerecord 和 activesupport 2.0.2,所以我使用了来自 rubygems.org 的 paperclip 2.3.8 gem。未定义的方法错误仍然存在,我真的不知道为什么。
现在...命令 ruby script/generate paperclip group_post photo
对我来说非常好。
我得到的当前错误完全是这样的:-
undefined method `has_attached_file' for #<Class:0xb67119f0>
我在使用 IRB 时观察到的一件有趣的事情是,require 'paperclip'
返回了 true
但我想知道为什么他们无法检测到我的 Rails 应用程序中的插件随附的方法。
相同的应用程序跟踪是:-
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'
app/models/group_post.rb:9
app/controllers/groups_controller.rb:27:in `show'
为了以防万一,完整跟踪是:-
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'
app/models/group_post.rb:9
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_file'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in `load_file'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in `require_or_load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in `load_missing_constant'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing_not_from_s3_library'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in `const_missing'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:471:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:471:in `const_missing'
app/controllers/groups_controller.rb:27:in `show'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/benchmark.rb:293:in `measure'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process_without_test'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/test_process.rb:15:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:281
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/server.rb:39
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
我的 groups_controller.rb 显示方法如下所示,这里第 27 行是 @group_post = GroupPost.new(params[:group_post])
:-
def show
@investor_group = InvestorGroup.find(params[:id])
@members = @investor_group.activated_members
# code taken from discuss method
investor_id = session['investor_id']
@investor = Investor.find(investor_id)
@members = @investor_group.activated_members
unless @current_user.is_an_existing_member_of_group(@investor_group)
flash[:notice] = "Please join this group to participate in discussions"
redirect_to :action => :show, :id => @investor_group and return
else
@group_post = GroupPost.new(params[:group_post]) # line 27, tried GroupPost.create also.. seems to be of no avail..
end
#@group_post = GroupPost.new(params[:group_post])
@group_post.investor_group_id = @investor_group.id
@group_post.post_by = investor_id
unless @group_post.message.blank?
if @group_post.save
flash[:notice] = 'Post was successfull'
else
flash[:notice] = 'Post was not successfull'
end
#redirect_to :action => :show, :id => @investor_group and return to change.. appropriately....
end
#if @group_post.message.blank?
# flash[:notice] = 'Post can\'t be blank.'
#end
@group_all_posts = GroupPost.find(:all, :conditions => [ 'investor_group_id = ?', "#{@investor_group.id}" ], :order => 'created_at DESC')
# code taken from discuss method
end
group_post 模型看起来像这样,第 9 行具有以下代码 has_attached_file :photo :-
类 GroupPost < ActiveRecord::Base 有很多:group_comments belongs_to :investor_group validates_presence_of:消息
#include回形针 需要“回形针” # 回形针 has_attached_file :photo # 第 9 行
结束
我尝试上传图片和帖子的部分 View 文件如下所示:-
<%form_for :group_post, @group_post, :url => {:action => :show},:html => {:multipart => 'true'},:id => 'new_post' do |f| -%>
<p><label>Start Discussion:</label><br><%=f.text_field :message%></p>
<%=f.file_field :photo%></p>
<p><%=submit_tag "Post"%></p>
<%end%>
我尝试了给出的内容:-
这个选项似乎不适用于我的情况,因为它似乎使用了 更高的 Rails 版本
Undefined method has_attached_file after Paperclip installation?
我尝试重启我的服务器,但它并没有解决我的问题;
我尝试了 include Paperclip - 但它似乎对我的情况没有帮助......
我在我的 group_post.rb 和我的 environment.rb 文件中添加了一个 require 作为 require “paperclip”。我仍然收到未定义的方法错误。我不知道为什么..
关于这个我尝试了 Imumar 的回形针分支,我在 git 克隆后手动将它粘贴到我的 vendor/plugins 目录中。我得到以下错误(我有一种感觉肯定会有依赖问题,因为他的版本可能只与更高的 rails 版本兼容:
mohnish@mohnish-desktop:~/UP/dev$ ruby script/server -p 4000
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:4000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:4000
** Starting Rails with development environment...
Exiting
/home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant Paperclip::CallbackCompatability::Rails20 (NameError)
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'
from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:118:in `included'
from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364:in `include'
from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364:in `send'
from /home/mohnish/UP/dev/vendor/plugins/paperclip/lib/paperclip.rb:364
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/UP/dev/vendor/plugins/paperclip/init.rb:1:in `evaluate_init_rb'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:79:in `evaluate_init_rb'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:75:in `evaluate_init_rb'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin.rb:39:in `load'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:33:in `load_plugins'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:32:in `each'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/rails/plugin/loader.rb:32:in `load_plugins'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:189:in `load_plugins'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:105:in `process'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:49:in `send'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/initializer.rb:49:in `run'
from /home/mohnish/UP/dev/config/environment.rb:16
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:147:in `rails'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:113:in `cloaker_'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `call'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `listener'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:99:in `cloaker_'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `call'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `initialize'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `new'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `run'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/mongrel-1.1.5/bin/mongrel_rails:281
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /home/mohnish/.rvm/gems/ruby-1.8.7-p334/gems/rails-2.0.2/lib/commands/server.rb:39
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /home/mohnish/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
mohnish@mohnish-desktop:~/UP/dev$
我真的很想知道我哪里出错了..
任何建议/见解将不胜感激。这对我来说很紧急,因为我有一项部署到期,我真的很高兴得到及时的答复/回应..
非常感谢..
最佳答案
有点相关,决定把它放在这里供 future 的谷歌员工使用。
在带有 bundler 的 Ruby 1.8.7 上使用 Rails 2.3.14。正如 thoughtbot 所建议的,我正在使用回形针 2.7,即我的 gemfile 包含:
gem "paperclip", "~> 2.7.0"
我还收到“未定义方法”错误。为我修复它的方法是将 paperclip.rb
文件放入 config/initializers
中,其中包含以下内容:
require "paperclip/railtie"
Paperclip::Railtie.insert
希望这会让一些人头疼。
关于ruby-on-rails - 使用 Ruby 1.8.7 的 Rails 2 的回形针 2.3.8 gem 的未定义方法 `has_attached_file',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6002414/
以下是一个非常简单的ruby服务器。 require 'socket' local_socket = Socket.new(:INET, :STREAM) local_addr = Socket.
我正在使用 OS X(使用 bash),并且是 unix 的新手。我想知道是否可以修改一些文件以便运行 ruby 程序,我不需要“ruby file.rb”,而是可以运行“ruby.rb”。 有理
我在用 Ruby 替换字符串时遇到一些问题。 我的原文:人之所为不如兽之所为。 我想替换为:==What== human does is not like ==what== animal does.
我想在一个循环中从 Ruby 脚本做这样的事情: 写一个文件a.rb(每次迭代都会改变) 执行系统(ruby 'a.rb') a.rb 将带有结果的字符串写入文件“results” a.rb 完成并且
我的问题是尝试创建一个本地服务器,以便我可以理解由我的新团队开发的应用程序。我的问题是我使用的是 Ruby 2.3.3,而 Gemfile 需要 2.3.1。我无法编辑 Gemfile,因为我被告知很
我有一个使用 GLI 框架用 Ruby 编写的命令行实用程序。我想在我的主目录中配置我的命令行实用程序,使用 Ruby 本身作为 DSL 来处理它(类似于 Gemfile 或 Rakefile)。 我
我的 Rails 应用 Controller 中有这段代码: def delete object = model.datamapper_class.first(:sourced_id =>
我正在寻找的解析器应该: 对 Ruby 解析友好, 规则设计优雅, 产生用户友好的解析错误, 用户文档的数量应该比计算器示例多, UPD:允许在编写语法时省略可选的空格。 快速解析不是一个重要的特性。
我刚开始使用 Ruby,听说有一种“Ruby 方式”编码。除了 Ruby on Rails 之外,还有哪些项目适合学习并被认可且设计良好? 最佳答案 Prawn被明确地创建为不仅是一个该死的好 PDF
我知道之前有人问过类似的问题,但是我该如何构建一个无需在前面输入“ruby”就可以在终端中运行的 Ruby 文件呢? 这里的最终目标是创建一个命令行工具包类型的东西。现在,为了执行我希望用户能够执行的
例如哈希a是{:name=>'mike',:age=>27,:gender=>'male'}哈希 b 是 {:name=>'mike'} 我想知道是否有更好的方法来判断 b 哈希是否在 a 哈希内,而
我是一名决定学习 Ruby 和 Ruby on Rails 的 ASP.NET MVC 开发人员。我已经有所了解并在 RoR 上创建了一个网站。在 ASP.NET MVC 上开发,我一直使用三层架构:
最近我看到 Gary Bernhardt 展示了他用来在 vim 中执行 Ruby 代码的 vim 快捷方式。捷径是 :map ,t :w\|:!ruby %. 似乎这个方法总是执行系统 Rub
在为 this question about Blue Ruby 选择的答案中,查克说: All of the current Ruby implementations are compiled to
我有一个 Ruby 数组 > list = Request.find_all_by_artist("Metallica").map(&:song) => ["Nothing else Matters"
我在四舍五入时遇到问题。我有一个 float ,我想将其四舍五入到小数点后的百分之一。但是,我只能使用 .round ,它基本上将它变成一个 int,意思是 2.34.round # => 2. 有没
我使用 ruby on rails 编写了一个小型 Web 应用程序,它的主要目的是上传、存储和显示来自 xml(文件最多几 MB)文件的结果。运行大约 2 个月后,我注意到 mongrel 进程
我们如何用 Ruby 转换像这样的字符串: 𝑙𝑎𝑡𝑜𝑟𝑟𝑒 收件人: Latorre 最佳答案 s = "𝑙𝑎𝑡𝑜𝑟𝑟𝑒" => "𝑙𝑎𝑡𝑜𝑟𝑟𝑒" s.u
通过 ruby monk 时,他们偶尔会从左侧字段中抛出一段语法不熟悉的代码: def compute(xyz) return nil unless xyz xyz.map {|a,
不确定我做错了什么,但我似乎弄错了。 问题是,给你一串空格分隔的数字,你必须返回最大和最小的数字。 注意:所有数字都是有效的 Int32,不需要验证它们。输入字符串中始终至少有一个数字。输出字符串必须
我是一名优秀的程序员,十分优秀!