愚蠢的问题?
<img alt="Phone_large" src="/system/photos/1/small/phone_large.jpg?1238845838" />
Run Code Online (Sandbox Code Playgroud)
为什么"?1238845838"被添加到图像路径?
如果没有它我怎么能得到我的路径/网址?
所以我开始学习Rails.现在Rails 3已经出局了,我想坚持学习Rails 3的做事方式.我想学习如何做的事情之一是如何使用第三方REST API /创建"mashup"应用程序来使用Web服务/工作.我只用PHP和预先构建的库完成了这样的小工作.
有人可以请我介绍一些资源,最佳实践,或者给我一个关于如何开始使用这些类型的API的快速课程吗?我应该使用什么宝石?一些示例代码让我开始将非常感激.
更新:我特意尝试使用Google Books API(未经过身份验证).由于此API没有客户端库,我想知道其他Ruby/Rails开发人员如何使用不带自己的Ruby库的API.这就是为什么我正在寻找一种更通用的解决方案来处理"填空"API.
更新:经过一番研究,我注意到了Net :: HTTP库.所有谈到它的教程都相当陈旧.这仍然是用于使用RESTful Web服务的最佳库吗?或者是否有更新的宝石使这更容易?我只想知道我应该使用哪个gem /库,以及如何使用返回的XML/JSON结果.
更新:此演示文稿非常有用.它提到了一堆不同的库,并显示了下面提到的一些库的示例:http://www.slideshare.net/pengwynn/json-and-the-apinauts
我有一个会议模型:
class Meeting < ActiveRecord::Base
has_one :location, :class_name => "MeetingLocation", :dependent => :destroy
accepts_nested_attributes_for :location
Run Code Online (Sandbox Code Playgroud)
然后我有一个MeetingLocation模型:
class MeetingLocation < ActiveRecord::Base
belongs_to :meeting
Run Code Online (Sandbox Code Playgroud)
我的新会议表格:
<%= form_for @meeting do |f| %>
<%= f.label :location %>
<%= fields_for :location do |l| %>
Name <%= l.text_field :name %>
Street <%= l.text_field :street %>
City <%= l.text_field :city, :class => "span2" %>
State <%= l.select :state, us_states, :class => "span1" %>
Zipcode <%= l.text_field :zip, :class => "span1" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
当我查看新会议表单时,位置字段为空!我只看到位置标签,但没有其他位置字段.我一直在寻找过去3个小时的解释,发现很多类似的问题,但没有运气.
谢谢.
我正在尝试使用paperclip将文件上传到s3,并在创建新对象并引用变量时出现此错误:
即:
a = Attachment.new
a.file
NameError: uninitialized constant AWS::S3::Connection
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:32
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:31:in `class_eval'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:31
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/storage.rb:131:in `extended'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:269:in `extend'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:269:in `initialize_storage'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:51:in `initialize'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:372:in `new'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:372:in `attachment_for'
from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:270:in `file'
from (irb):6
Run Code Online (Sandbox Code Playgroud)
以下是Attachment模型的样子:
class Attachment < ActiveRecord::Base
belongs_to :post
has_attached_file :file,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/uploads/:attachment/:id/:style/:basename.:extension",
:bucket => 'bucketname',
:s3_permissions => :public_read
end
Run Code Online (Sandbox Code Playgroud) 默认情况下,会话存储在浏览器cookie(:cookie_store)中,但您也可以指定其中一个包含的存储(:active_record_store,:mem_cache_store或您自己的自定义类.请给我构建自定义类的方法
config.action_controller.session_store = :your_customer_class
Run Code Online (Sandbox Code Playgroud) 我正在使用rails 3和黄瓜,除了这个小问题外,一切顺利
Given I am on the "edit automobile" page
No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError)
Run Code Online (Sandbox Code Playgroud)
现在路径在paths.rb中设置为edit_automobile_path
在routes.rb我有汽车作为资源,我搭建了它
所以请告诉我我错过了什么,显然路线是定义和匹配的,因为我跑了耙路线并看到了路线.
请指出我正确的方向