简体   繁体   中英

In Rails, how to update record from show view (and not edit)?

After many googling, I can't find something relevant... I have a student model with view (edit, index, show). Edit view are only viewed by student and index and show views are viewed by admin staff. I would the admin staff could check a checkbox on the show view to "sign" or say "done" at this record. If the check box is checked, i would a "sign information" like time.now and current_user name. I should save this in the student record. How to do that because show is a "get" form and I would a "post" action...

Could you help me ?

Many thanks in advance

Nicolas

The name of the page is not relevant, you can put a form or "action" link any page. To just show something to administrators, you could create a method admin_user in a helper file which checks if the current user is an admin, and then put the following code in your view:

<% if admin_user? %>
  <%= link_to "Check", sign_path %>
<% end %> 

You could then create a route and controller action "Sign" which will mark a specific record as signed. You could also use a form in the above code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM