我正在开发具有用户,事件(用户创建),最终,用户将能够订阅/参加这些事件的示例Rails应用程序。Rails查看不刷新后redirect_to
我有一个表,用户可以在事件行中单击link_to按钮时订阅和取消订阅事件。 link_to从event_controller中调用了一个重定向到current_path的方法,但是当我单击该按钮时,该视图没有任何反应,但似乎服务器呈现该视图。
这是因为我从event_controller调用它,但使用用户的演出控制器?
LOG:
Rendered users/show.html.erb within layouts/application (17.1ms)
用户> show.html.erb
<% if current_user?(@user) %>
<td><%= link_to "Delete", e, method: :delete,
data: { confirm: "You sure?" } %></td>
<% else %>
<% if attendingEvent?(current_user, e.id) %>
<td><%= link_to "Not Going", events_remove_event_to_attend_path(event_id: e.id, event_owner_id:@user.id, current_path:request.fullpath), remote: true %></td>
<% else %>
<td><%= link_to "I Want To Go", events_add_event_to_attend_path(event_id: e.id, event_owner_id:@user.id, current_path:request.fullpath), remote: true %></td>
<% end %>
<% end %>
events_controller.rb
def add_event_to_attend
puts attend_params
puts request.fullpath
@attend = Attendee.new
@attend.event_id = (attend_params[:event_id])
@attend.user_id = current_user.id
if @attend.save
flash[:success] = "You created an assocations"
redirect_to(attend_params[:current_path])
puts 'saved'
else
flash[:danger] = "You did not create the event"
puts 'not saved'
end
end
def remove_event_to_attend
@event_to_delete = Attendee.find_by_user_id_and_event_id(current_user.id,params[:event_id])
@event_to_delete.destroy
redirect_to(attend_params[:current_path])
end
嗨,欢迎来到Stack Overflow。所以......我注意到你已经在代码中放了一些'puts' ......你在服务器日志/终端屏幕上看到了什么?其次:你的rjs模板有什么?你有rjs模板吗?你已经将链接设置为远程 - 这意味着你发送了一个js请求,如果你发回一些js来告诉它这样做,浏览器只会改变它的视图。或者,您可以通过从链接中删除'remote:true'来快速解决此问题,然后重定向将正常工作... –