Render form partial in a different controller (not nested)

前端 未结 2 1538
既然无缘
既然无缘 2020-12-29 07:53

I have two models generated with generate scaffolding, one is a LogBook the other is LogEntry. I want to render the form partial for LogEntry on the LogBook show page. Whe

2条回答
  •  萌比男神i
    2020-12-29 08:33

    You can render whatever partial you want as long as you give it's path from the view folder:

     <%= render :partial => '/log_entries/form', :log_entry => @log_book.log_entries.build %>
    

    Your path must begin with a / to let Rails know you're relative to the view folder.

    Otherwise it's assumed to be relative to your current folder.

    As a sidenote, it's good practive to avoid using instance variables in partial, you did it right then.

    Just seen you have an error in your partial's form:

     :Text
    

    Should not be a valid column name of your model. Try :text

提交回复
热议问题