Rails 3, how add a associated record after creating a primary record (Books, Auto Add BookCharacter)

前端 未结 2 1707
无人共我
无人共我 2021-02-04 12:52

Rails newbie... trying to understand the right way to do things...

In my app users can create a Book ( I have that working)

What I want to happen is when a user

2条回答
  •  别跟我提以往
    2021-02-04 13:07

    I prefer something like (if User has_many Book):

    def create
     @book = current_user.books.new(params[:book])
     respond_to do |format|
      if @book.save
      …
    

提交回复
热议问题