无法在主页上显示邀请邀请框

时间:2012-07-02 16:14:14

标签: ruby-on-rails models

我想发布测试版邀请函。但我无法在主页上看到邀请表。

/static_pages/home.html.erb :(很快)

<% if signed_in? %>
  <div class="row">
    <aside class="span2">
      <section>
                <%= render 'shared/invitation_form' %>
      </section>
    </aside>
    <div class="span6 hero-unit">       
            <ol class="topics-signedin">
            <%= render 'shared/topics' %>
            </ol>
    </div>
  </div>  
<% else %>
  <div class="row">
        <div class="span10">
            <div class="center hero-unit">
                <h2>Giripedia</h2>  
                        <ol class="topics">
                        <%= render 'shared/topics' %>
                        </ol>
                <%= link_to "Üye Olun!", signup_path, 
                                class: "btn btn-large btn-primary center" %> 
        <p>Sitemiz ş....</p>

                <% form_for Invitation.new do |f| %>
                    <p>
                        <%= f.label :recipient_email, "Emailiniz:" %>
                        <%= f.text_field :recipient_email %>
                        <%= f.submit 'Gönder' %>
                    </p>
                <% end %>
            </div>
        </div>
<% end %> 

rake routes:

new_invitation GET    /invitations/new(.:format)            invitations#new
edit_invitation GET    /invitations/:id/edit(.:format)       invitations#edit
     invitation GET    /invitations/:id(.:format)            invitations#show
                PUT    /invitations/:id(.:format)            invitations#update
                DELETE /invitations/:id(.:format)            invitations#destroy

我的static_pages_controller.rb:

  def home
        if signed_in?
        @topic = current_user.topics.build if signed_in?
        end
        @topics = Topic.paginate :page => params[:page], :per_page => 20
    @invitation = Invitation.new
  end

我的_invitation_form.html.erb:

<% form_for @invitation do |f| %>
  <p>
    <%= f.label :recipient_email, "Arkadaşının email adresi" %><br />
    <%= f.text_field :recipient_email %>
  </p>
  <p><%= f.submit "Davet et!" %></p>
<% end %>

日志显示:

 (0.1ms)  SELECT COUNT(*) FROM "topics" WHERE "topics"."user_id" = 1
  Rendered shared/_user_info.html.erb (2.4ms)
  Rendered shared/_error_messages.html.erb (0.4ms)
  Rendered shared/_topic_form.html.erb (2.9ms)
  Rendered shared/_invitation_form.html.erb (1.8ms)
  Topic Load (0.1ms)  SELECT "topics".* FROM "topics" ORDER BY topics.created_at DESC LIMIT 20 OFFSET 0..

但它没有显示User.form。你有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你错过了_invitation_form.html.erb中的=。尝试:

<%= form_for @invitation do |f| %>
  <p>
    <%= f.label :recipient_email, "Arkadaşının email adresi" %><br />
    <%= f.text_field :recipient_email %>
  </p>
  <p><%= f.submit "Davet et!" %></p>
<% end %>

同样在home.html.erb的<% form_for ... %>