简体   繁体   English

Rails调用页面内的edit动作

[英]Rails calling the edit action within a page

I am sure this is common requirement but I am new to rails and I have tried searching for the problem but haven't had much luck. 我确信这是常见的要求,但是我是Rails的新手,我曾尝试寻找问题,但是运气不高。

I have a form and I have pre-populated it with values from the database for the specific entry. 我有一个表单,并且已经使用数据库中用于特定条目的值预先填充了该表单。 The user should be able to change those values and then hit the 'edit' button which then then go and edit the values in the database. 用户应该能够更改这些值,然后单击“编辑”按钮,然后再去编辑数据库中的值。

I want to call the edit action from within a page without using the standard /1/edit url path. 我想在不使用标准/ 1 / edit URL路径的情况下从页面内调用edit操作。 Basically I want to call .find(params[:id]) by passing the id of a particular entry directly into the method. 基本上,我想通过将特定条目的ID直接传递给方法来调用.find(params [:id])。

What is the best 'rails way' of doing this? 这样做的最佳“轨道方式”是什么?

Thanks for your help. 谢谢你的帮助。

This particular method is being called within a button press? 在按下按钮时会调用此特定方法吗? A link click? 链接点击? A focus change? 重点改变了吗?

You can always send parameters to the server like this: 您始终可以像这样将参数发送到服务器:

<%= link_to "Your action", yourcustomaction_path(:id => @object.id) %> 

Or like this: 或像这样:

<%= text_field_tag "yourattribute", params[:this_field_attribute] %>

You don't have to always call the default edit action, you can simply create another route in routes.rb 您不必总是调用默认的编辑操作,只需在routes.rb中创建另一个路由

Or you could go one step further and use the in_place_editing gem. 或者,您可以更进一步,然后使用in_place_editing gem。 No need for a button and remote forms. 无需按钮和远程表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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