저는 루비 문서의 form_for를 통해 읽으려고 시도했지만 차이점을 이해하는 것은 여전히 어렵습니다. @post와 : post의 차이점은 무엇입니까?
new.html.erb보기 :post
작품을로드
@post
하지 않습니다.
This is Post's new.html.erb
<%= form_for(:post) do |f| %>
<%= f.text_area :note, value: "Say something" %><br>
<%= f.submit "Post" %>
<% end %>
PostController :
class PostsController < ApplicationController
before_action :signed_in_user, only: [:new, :create]
def index
@posts = Post.all
end
def new
end
def create
@post = current_user.posts.build
puts "This is #{@post.user_id} user"
redirect_to posts_path if @post.save #post/index.html.erb
end
def destroy
end
private
def signed_in_user
redirect_to signout_path, notice: "Please sign in." unless signed_in?
end
end
guides.rubyonrails.org를 사용해 보셨습니까? –
가능한 복제본 http://stackoverflow.com/questions/957204/instance-variable-vs-symbol-in-ruby-on-rails-form-for –
예, 명확하지 않았습니다. – funfuntime