Nie chce wyświetlić create_at

a wieć sprawa wyglada tak

<% div_for post do %>

  • #<%= @i %>. <% @i = @i+1 %> <%= link_to_unless_current h(post.title), post %>

    <%= textilize(post.body) %>

       <p class="right">
        <% if post.comments.count.to_i == 1 %>
          <%= post.comments.count %> comment</p>
        <% else %>
          <%= post.comments.count %> comments</p>
        <% end %>
       <small class="right"><%= post.created_at.strftime '%d %m, %Y' unless post.created_at.nil? %></small>
     </div>
    
    <% end %>

    no i w zaden sposob nie chce wyswietlic daty, chodz inne dane z bazy wyciaga. Dane na pewno sa i jak sie wyswietli je pzrze <% debug %>

    to je widzi

    baza to postgres,

  • post.created_at.strftime ‘%d %m, %Y’ unless post.created_at.nil? jest przekombinowane troche.

    1. Uzywaj () w tego typu konstrukcjach, w zasadzie nie widac czy ‘%d %m, %Y’ unless post.created_at.nil? to caly argument czy tylko ‘%d %m, %Y’, nie uzywanie nawiasow w takich przypadkach sprawia ze kod jest nieczytelny
    2. Nie musisz uzywac .nil? w przypadku gdy chcesz sprawdzic warunek, latwiej jest zrobic po prostu unless post.created_at niz unless post.created_at.nil?

    Popraw powyzsze bledy i upewnij sie ze dany post zawiera created_at np poprzez <%= debug(post.created_at) %>

    Hmm te cudo powstaly jak juz nad tym dlugo siedzialem

    normalnie dalem teraz

    <%= debug(post.created_at) %>

    no i pojawilo sie tylko :

    trzy kreseczki :confused: dziwne dla mnie bo samo

    <%= debug(post) %>
    daje

    — !ruby/object:Post
    attributes:
    updated_at: 27.12.2008 22:02:24.77136
    title: Who are we?
    body: Accent Media Group Is the personal portfolio of Brad Haynes, a web designer / developer currently working at Paramore | Redd Online Marketing in Nashville, TN. Building websites for several years now, Brad loves to spend his time tinkering with small minute details that no one will probably ever notice. And because of the amount of work involved in all the projects, Accent Media Group includes the work of professional copywriters, programmers, and other web geeks to ensure your project gets the attention it deserves.
    id: “1”
    created_at: 27.12.2008 18:36:32.547313
    attributes_cache: {}

    co to moze byc?

    i tak dalej

    — !ruby/object:Post
    attributes:
    updated_at: 27.12.2008 18:37:01.160572
    title: Sites Built to Last.
    body: "Every site developed by Accent Media is built according to W3C standards using tableless CSS designs. This means that not only will your sites stand the test of time, but having them designed to standards ensures future changes and revisions can be implemented without the headache (and more importantly, with minimal cost). "
    id: “2”
    created_at: 27.12.2008 18:37:01.160572
    attributes_cache: {}

    wiec pytanie jest czemu moge odwolac sie do title body przez post a nie moge do created_at ?

    prosze o jakas podpowiedz bo juz 3 dzien mnie to meczy

    Potestuj sobie te wszystkie opcje w konsoli railsów, zobacz czy możesz wyświetlić samą datę bez formatowania a potemz formatowaniem

    A co bedziesz mial z tym ?

    [code]A:<%= debug(post.attributes[:created_at]) %>

    B:<%= debug(post.created_at) %>[/code]

    A:<%= debug(post.attributes[:created_at]) %>

    B:<%= debug(post.created_at) %>

    dało

    A:

    B:

    wiec dalej nic :confused:

    moze jest cos wyzesz wszystko wyglada tak:

    w
    layout/posts… mam:
    <%= yield %>

    pozniej w posts/index…
    <%= render :partial => @posts.reverse %>

    w _post

    <% div_for post do %>

  • #<%= @i %> <% @i = @i+1 %> <%= link_to_unless_current h(post.title), post %>

    <%= textilize(post.body) %>

       <p class="right">
        <% if post.comments.count.to_i == 1 %>
          <%= post.comments.count %> comment</p>
        <% else %>
          <%= post.comments.count %> comments</p>
        <% end %>
        <small class="right"><%= (post.created_at) %></small>
    
        A:<%= debug(post.attributes[:created_at]) %>
    
        B:<%= debug(post.created_at) %>
    
     </div>
    
    <% end %>
  • A w script/console ten sam post jakie ma created_at?

    no właśnie sprawdziłem i w console

    @posts = Post.find(:all)
    => [#<Post id: 2, title: “Sites Built to Last.”, body: “Every site developed by Accent Media is built accor…”, created_at: nil, updated_at: nil>, #<Post id: 1, title: “Who are we?”, body: “Accent Media Group Is the personal portfolio of Bra…”, created_at: nil, updated_at: nil>]

    są nil ech teraz to juz w ogole głupi jestem

    debug widzi jak ma debug(post)

    w bazie jest

    a tutaj nil ciagle ;/

    moze cos z postgresem i formatem tego tam ?

    A:<%= debug(post.attributes[:created_at]) %>

        B:<%= debug(post.created_at) %>
    

    jaki jest tego wynik ?

    masz odpowiedz kilka postow wyzej :

    a w skrocie w obu przypadkach jest :

    Jakich Rails uzywasz, jakich pluginow. Czy napewno consola ma ten sam environment co aplikacja ? Czy w bazie masz cokolwiek w kolumnach created_at, updated_at. Troch po omacku… ale dam sobie reke uciac ze blad jest jakis trywialny. Upewnij sie tez w ktorym kontekscie <%= debug(post) %> ma jakies wartosci w created_at. tzn przetestuj poczwszy od kontrolera:

    render :text => Post.find(:all).inspect

    potem layout:
    <%= debug(@posts) %> itd :stuck_out_tongue:

    No z tego co się tu pochwalił konsolą wynika, że ma wynilowane pola created_at i updated_at…

    No tak ale czemu? W bazie dane sa, lądują tam z automatu, bo oba pola zostaly stworzone jak sie mozna domyslic automatycznie i jak zapisuje cos na stronie, dodaje jakis post to dane tam laduja razem z tymi dwoma polami. Tylko czemu nie chce sie to pojawic z powrotem. Co do tego jka to jest zorganizowane itp:

    rails -v
    Rails 2.2.2

    serwer mongrel

    postgres --version
    postgres (PostgreSQL) 8.2.7

    uname -a
    Linux gotar 2.6.22-gentoo-r5 #9 SMP Sun Feb 17 00:17:41 CET 2008 i686 AMD Athlon™ XP 2600+ AuthenticAMD GNU/Linux
    Gentoo tak w nawiasie

    gem list

    *** LOCAL GEMS ***

    abstract (1.0.0)
    actionmailer (2.2.2, 2.1.2)
    actionpack (2.2.2, 2.1.2)
    activerecord (2.2.2, 2.1.2)
    activeresource (2.2.2, 2.1.2)
    activesupport (2.2.2, 2.1.2)
    addressable (2.0.1)
    cgi_multipart_eof_fix (2.5.0)
    daemons (1.0.10)
    data_objects (0.9.9)
    diff-lcs (1.1.2)
    dm-aggregates (0.9.8)
    dm-core (0.9.8)
    dm-migrations (0.9.8)
    dm-sweatshop (0.9.8)
    dm-timestamps (0.9.8)
    dm-types (0.9.8)
    dm-validations (0.9.8)
    do_postgres (0.9.9)
    do_sqlite3 (0.9.9)
    erubis (2.6.2)
    extlib (0.9.9)
    fastthread (1.0.1)
    gem_plugin (0.2.3)
    haml (2.0.6)
    highline (1.5.0)
    hoe (1.8.2)
    json_pure (1.1.3)
    launchy (0.3.2)
    mailfactory (1.4.0)
    merb (1.0.6.1)
    merb-action-args (1.0.6.1)
    merb-assets (1.0.6.1)
    merb-auth (1.0.6.1)
    merb-auth-core (1.0.6.1)
    merb-auth-more (1.0.6.1)
    merb-auth-slice-password (1.0.6.1)
    merb-cache (1.0.6.1)
    merb-core (1.0.6.1)
    merb-exceptions (1.0.6.1)
    merb-gen (1.0.6.1)
    merb-haml (1.0.6.1)
    merb-helpers (1.0.6.1)
    merb-mailer (1.0.6.1)
    merb-more (1.0.6.1)
    merb-param-protection (1.0.6.1)
    merb-slices (1.0.6.1)
    merb_datamapper (1.0.6.1)
    merb_helpers (0.9.7)
    mime-types (1.15)
    mongrel (1.1.5)
    ParseTree (3.0.2)
    postgres (0.7.9.2008.01.28)
    rack (0.4.0)
    rails (2.2.2, 2.1.2)
    rake (0.8.3)
    randexp (0.1.4)
    RedCloth (4.1.1)
    rspec (1.1.11)
    ruby-postgres (0.7.1.2006.04.06)
    ruby2ruby (1.2.1)
    rubyforge (1.0.1)
    RubyInline (3.8.1)
    sexp_processor (3.0.0)
    templater (0.5.0)
    thor (0.9.9)
    webrat (0.3.2)
    ZenTest (3.11.0)

    development: &defaults
    adapter: postgresql
    database: blog
    username: gotar
    password:
    host: localhost

    controller:
    class PostsController < ApplicationController

    before_filter :authorize, :except => [:index, :show]

    GET /posts

    GET /posts.xml

    def index
    @posts = Post.search(params[:search])
    if @posts.size.zero?
    redirect_to ("/nothing")
    else
    respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @posts }
    format.atom
    end
    end
    end

    GET /posts/1

    GET /posts/1.xml

    def show
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @post }
    end
    

    end

    model:
    class Post < ActiveRecord::Base
    validates_presence_of :body, :title
    has_many :comments

    def self.search(search)
    if search
    @ile = find(:all, :conditions => [‘title || body ILIKE ?’, “%#{search}%”])
    else
    find(:all)
    end
    end
    end

    widok:
    <% div_for post do %>

  • #<%= @i %> <% @i = @i+1 %> <%= link_to_unless_current h(post.title), post %>

    <%= textilize(post.body) %>

       <p class="right">
        <% if post.comments.count.to_i == 1 %>
          <%= post.comments.count %> comment</p>
        <% else %>
          <%= post.comments.count %> comments</p>
        <% end %>
        <small class="right"><%= (post.created_at) %></small>
    
    <% end %>
  • render :text => Post.find(:all).inspect
    [#, #]

    <%= debug(@posts) %>

    • !ruby/object:Post
      attributes:
      updated_at: 27.12.2008 18:37:01.160572
      title: Sites Built to Last.
      body: "Every site developed by Accent Media is built according to W3C standards using tableless CSS designs. This means that not only will your sites stand the test of time, but having them designed to standards ensures future changes and revisions can be implemented without the headache (and more importantly, with minimal cost). "
      id: “2”
      created_at: 27.12.2008 18:37:01.160572
      attributes_cache:
      created_at:
      comments:
      • !ruby/object:Comment
        attributes:
        name: Hmm
        updated_at: 27.12.2008 19:07:03.239389
        body: “Fajnie jak by zadzia\xC5\x82a\xC5\x82o”
        post_id: “2”
        url: “”
        id: “3”
        email: “”
        created_at: 27.12.2008 19:07:03.239389
        attributes_cache: {}

    ?? nikt nie ma pomysłu na to, może chociaż jakaś wskazówka gdzie szukac?

    Mi sie juz pomysly skonczyly, ale dalej chetnie pomoge :wink: Wiec ostatnie co mozesz zrobic to spakowac caly katlaog aplikacji i mi go wystawic tutaj a ja sprawdze czy faktycznie umnie tez tak dziala(tzn. zle dziala), jesli tak :wink: znajde blad, jesli wszystko dziala znacyz ze masz environment ruby i rails skopany :stuck_out_tongue:

    Ok poszlo na mail na gmailu

    Nie wiem czy to nie wina postgresa moze? ale w sumie niby czemu miala by byc bo opcje tez mi sie skonczyly ;/