你好,我想表现出/notes/show_html.slim @detail,但我有错误缺少的部分细节/ _detail与在/notes/show.html.slim缺少导轨部分
我怎么能输出@detailroutes.rb中
Rails.application.routes.draw do
root 'static_pages#home'
match '/about_me', to: 'static_pages#about', via: 'get'
devise_for :users
resources :users, only: [:index, :show]
resources :notes do
resources :details
end
end
details_controller.rb
class DetailsController < ApplicationController
def new
@note = Note.find(params[:note_id])
@detail = Detail.new
end
def create
@note = Note.find(params[:note_id])
@detail = @note.details.build(detail_param)
if @detail.save
redirect_to note_path(@note)
end
end
def destroy
@note = Note.find(params[:note_id])
@detail = @note.details.find(params[:id])
@detail.destroy
redirect_to note_path(@note)
end
private
def detail_param
params.require(:detail).permit(:body)
end
end
和视图
/notes/show.html.slim
#note
#post_content
.show
h1 = @note.title
= render @note.details #or = render 'details/show'?
.date
p Created #{time_ago_in_words(@note.created_at)} ago
hr
-if @note.user_id == current_user.id
p=link_to 'Edit', edit_note_path(@note), class: 'btn btn-primary'
p=link_to 'delete', note_path, method: :delete, data: { confirm: "Delete note?" }, class: 'btn btn-primary'
p=link_to 'Add details', new_note_detail_path(@note), class: 'btn btn-primary'
hr
.body
p #{@note.body}
/details/show.html.slim
div class="details"
p #{@detail.body}
**谢谢!**工作! –