嗨,当用户单击某个链接时,我正在尝试更新我的数据库(PostgreSQL)中的值,尽管我所拥有的工作正常,但我认为它不是最佳实践。如果有人能展示我如何更好地实现这一目标,那就太好了
看法
%ul.button-group.round.even-3
%li= link_to '<i class="general foundicon-checkmark"></i>'.html_safe, accept_availability_path(a), :method => 'put', :remote => true, :class => 'button success tiny', :id => a.id, :disable_with => ''
控制器
def accept
@availability = Availability.find(params[:id])
@availability.available= true
respond_to do |format|
if @availability.update_attributes(params[:availability])
format.html { render :nothing => true }
format.js
else
format.html { render :action => "edit" }
format.js
end
end
end
路线
resources :availabilities do
put 'accept', :on => :member
put 'decline', :on => :member
end