English 中文(简体)
使用纽顿语连接一种方法吗?
原标题:using button_to to link to a method, can it be done?

是否有可能与一种不同模式内的方法联系起来? 在纽特州执行新闻,还是采取另一种做法,如在控制者采取行动?

工作人员模式内的方法:

def clearleave
self.where("grade =  1 ").update_all(:leave_balance => 22)
self.where("grade =  2 ").update_all(:leave_balance => 25)
self.where("grade =  3 ").update_all(:leave_balance => 30)
self.where("grade =  4 ").update_all(:leave_balance => 35)
end

1. 在对不同模式的看法中:

<%=button_to "Clear absences", {:controller => :staffs, :action => :clearleave}   %>
最佳回答

铁路以《示范观点》主计长模式为基础。 这意味着,这些请求(例如浏览器的粗体)由你的控制人处理。 主计长将从模型中收集所需数据,并将其传达给意见以显示。

你可能打算做的是:

路线:

resources :staff do
  member do
    post :clearleave
  end
end

主计长:

# StaffController
def clearleave
  @staff = Staff.find(params[:id])
  @staff.clearleave # this calls the method in your model
  # here you could redirect to e.g. the show page for your staff
  # redirect_to staff_path(@staff), :notice => "Cleared successfully"
end

阁下认为:

<%= button_to "Clear absences", clearleave_staff_path(@staff) %>
<!-- not sure if a ", :method => :post" is required here as well -->
<!-- in rails 3 a link_to should also work -->
<%= link_to "Clear absences", clearleave_staff_path(@staff), :method => :post %>
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签