0

我一直在尝试实现一个让我头疼好几天的功能(rails newb)。

我有一个由用户组成的应用程序,并且能够与特殊用户安排预订。我在特殊用户个人资料页面上放置了一个“计划预订”链接,该链接应该创建(1)一个“预订”对象和(2)创建预订对象的一个​​子对象(booking.user = 特殊用户)。第二部分是为了以后只有 booking.users 才能访问 booking 对象。

以下是我失败的尝试。

No route matches [GET] "/users/2/book_person"

耙路线:

book_person_user POST /users/:id/book_person(.:format)

路线:

resources :users do
 member do
  post :book_person, :controller => "bookings", :action => "book_person"
 end
end

Booking_controller

def book_person
@booking = Booking.new
@booking.name = "Booking with #{params[:id]}"
if @booking.save
  @user = User.find(params[:id])
    if not @user.participant_of?(@booking)
      @booking.users << @user
      flash[:notice] = 'User was successfully added to booking'
    else
      flash[:error] = 'User was already part of booking'
    end
    redirect_to @booking 
else
  flash[:notice] = "Could not add booking"
  redirect_to @booking
end

结尾

用户个人资料页面上的链接以预订该用户:

<%= link_to "Book Sessions", book_person_user_path, class: "btn btn-large" %>
4

1 回答 1

1

试试这个:

<%= link_to "Book Sessions", book_person_user_path, :method => :post, class: "btn btn-large" %>
于 2013-03-12T18:38:22.383 回答