Render form partial in a different controller (not nested)

前端 未结 2 1539
既然无缘
既然无缘 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条回答
  • 2020-12-29 08:27

    Try switching the render method as follows:

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

    Using just render works when passing an instance variable of the object. However, since you're specifying a file, it's best to use the option.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题