0

ユーザーのプロフィール ページにアクセスすると、これが表示されます。たとえば、localhost:3000/users/1...

ここで1行目で取得します

1: <%= form_for(@micropost) do |f| %>
2:   <%= render 'shared/error_messages', object: f.object %>
3:   <div class="field no-indent">
4:     <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>

それで、私は2つのマイクロポストフォームを持っています.1つはここにあります

<%= form_for(@micropost, :html => { :id => "sale" }) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field no-indent">
    <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
    <%= hidden_field_tag 'micropost[kind]', "sale" %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

そしてもう一つはここにあります

<%= form_for(@micropost) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field no-indent">
    <%= f.text_area :content, placeholder: "What's something else you want to buy?" %>
    <%= hidden_field_tag 'micropost[kind]', "purchase" %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

これが私のルートです。

SampleApp::Application.routes.draw do
  resources :users do
    resources :comments
    member do
      get :following, :followers
    end
  end
  resources :sessions, only: [:new, :create, :destroy]
  resources :microposts, only: [:create, :destroy] do
    resources :comments
    resources :kind
  end
  resources :relationships, only: [:create, :destroy]

  root to: 'static_pages#home'

  match '/signup',  to: 'users#new'
  match '/signin',  to: 'sessions#new'
  match '/signout', to: 'sessions#destroy', via: :delete

  match '/help',    to: 'static_pages#help'
  match '/about',   to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact'

ここにページ自体のコードがあります(ユーザーが表示)

      <section>
        <%= render 'shared/user_info' %>
      </section>

      <section>
        <div id= "purchases">
          <%= render 'shared/micropost_form_purchase' %>
        </div>
        <div id="sales">
          <%= render 'shared/micropost_form_sale' %>
        </div>
      </section>


<% provide(:title, @user.name) %>
<div class="row">
  <aside class="span4">
    <section>
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
    </section>
  </aside>
  <div class="span8">

    <% if @user.microposts.any? %>
      <h3>Purchases I am interested in (<%= @user.microposts.count %>)</h3>
      <ol class="microposts">
        <%= render @microposts %>
      </ol>
      <%= will_paginate @microposts %>
    <% end %>
  </div>
</div>

また、空のオブジェクトをフォームに渡す方法がわかりませんか? オブジェクトを作成するフォームの要点ではありませんか?

4

1 に答える 1

0

According to the article which I stumbled upon today it may be that the object you are passing to form_for (@micropost in this case) is nil or empty.

Here's the mentioned article: http://schneems.com/post/31460949407/raise-hell-better-programming-through-error-messages

于 2012-09-14T23:08:24.003 に答える