English 中文(简体)
铁路:日间田不 f价值
原标题:rails: datetimes fields do not fetch the values

我写了一部法典,其标题是: 法典如下。 它从未注明日期。 我做了任何错误的事情。 该法典如下:

    acts_as_api

    api_accessible :bill_corrections do |inv|
       inv.add :common_date, :as => :recieved_date, :if => lambda{|u|u.date_type_code=="RECVD"}
       inv.add :common_date, :as => :actual_date, :if => lambda{|u|u.date_type_code=="ARRIV"}
  end

我为时地绘制了图

create_table "item_dates", :force => true do |t|
    t.integer  "item_date_id",   :limit => 10
    t.string   "date_type_code"
    t.datetime "common_date"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
最佳回答

我是行为制造者。 我用最低限度的铁路机对你的使用进行了尝试,并为我工作。 例如,Xml的答复:

<users type="array">
  <user>
    <first-name>Me</first-name>
    <recieved-date type="datetime">2011-10-07T08:20:02Z</recieved-date>
  </user>
  <user>
    <first-name>Me2</first-name>
    <actual-date type="datetime">2011-10-07T08:20:52Z</actual-date>
  </user>
</users>

模型中的一皮模板就是这样:

api_accessible :test_dates do |t|
  t.add :first_name
  t.add :common_date, :as => :recieved_date, :if => lambda{|u|u.date_type_code=="RECVD"}
  t.add :common_date, :as => :actual_date, :if => lambda{|u|u.date_type_code=="ARRIV"}
end

而这是用户的垃圾堆放场:

[
    [0] #<User:0x0000010b859308> {
                    :id => 1,
            :first_name => "Me",
             :last_name => "Too",
                   :age => nil,
                :active => nil,
            :created_at => Fri, 07 Oct 2011 08:20:19 UTC +00:00,
            :updated_at => Fri, 07 Oct 2011 08:20:19 UTC +00:00,
        :date_type_code => "RECVD",
           :common_date => Fri, 07 Oct 2011 08:20:02 UTC +00:00
    },
    [1] #<User:0x0000010b858688> {
                    :id => 2,
            :first_name => "Me2",
             :last_name => "Too2",
                   :age => nil,
                :active => nil,
            :created_at => Fri, 07 Oct 2011 08:20:45 UTC +00:00,
            :updated_at => Fri, 07 Oct 2011 08:20:53 UTC +00:00,
        :date_type_code => "ARRIV",
           :common_date => Fri, 07 Oct 2011 08:20:52 UTC +00:00
    }
]

Did you check that you use the controller helpers correctly?

def index
  @users = User.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render_for_api :test_dates, :xml => @users, :root => :users  }
    format.json { render_for_api :test_dates, :json => @users, :root => :users }
  end
end

我希望这一帮助:

Further debugging could include: * What happens if you remove the :if options? * What does puts u.date_type_code say if you put it in the :if options blocks?

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签