Rails 2 - partial: what does @comment = Comment.new mean?

I am working on a tutorial with the following code:

<h3>New Comment</h3>
   <%= render :partial => @comment = Comment.new,
   :locals => { :button_name => "Create" } %>

I believe that 'render: partial => @comment' works like 'render: partial => "comment" ,: object => @comment'

Where is "= Comment.new" located? This is short for: object?

Alan

+3
source share
2 answers

In terms of Ruby

@obj = Object.new # returns @obj

So, you are processing a partial comment and creating a new comment object with which it can work simultaneously.

+6
source

See the http://apidock.com/rails/ActionView/Partials section "Rendering Objects Using RecordIdentifier":

# <%= render :partial => "accounts/account", :locals => { :account => @buyer } %>
<%= render :partial => @account %>

, . + ( ) , . :

  • .
  • render: partial = > 'mypartial',: locals = > {...}
+3

Source: https://habr.com/ru/post/1752354/


All Articles