Link directly to edit form

11 views
Skip to first unread message

Jim Crate

unread,
Jul 25, 2018, 12:35:15 AM7/25/18
to actives...@googlegroups.com
Is there a way to link directly to the edit form for a record? I know I can pass a param and use conditions_for_collection to filter the list to the record I want, but it would be nice if I could open the edit form automatically as well. I can probably come up with some javascript to count the table rows and trigger an action if there’s only 1, but maybe there’s a better way to do this.

If the edit form could be displayed by itself, especially embedded in a page with other content, that could be useful too. I could also use javascript to run the edit action like the listing does, but I’m not sure how much of the styling is linked to the table or higher-level containers

Any pointers would be appreciated.

Jim Crate

Sergio Cambra

unread,
Jul 25, 2018, 6:16:49 AM7/25/18
to actives...@googlegroups.com
Hi Jim

I'm not sure if I get what you ask for.

URL to edit form it's /controller/id/edit, it will open edit form in page. If
you ask for an url listing one row and open edit form, there is no one, but
there is url to listing one row (/controller/id/list), you can override
list.html.erb and add JS to open edit link, e.g.:

<%= render :super %>
<% if params[:id] %>
<script type="text/javascript">
$(document).ready(function() {
$('a.edit.as_action').click();
});
</script>

To embed activescaffold in another page you can use render active_scaffold:
controller_name, it will use JS to load controller index, you may load a
different action, although it will render layout, because activescaffold has
code to disable layout in index action only when loading embedded.

You can add to your view:

<%= render active_scaffold: controller_name, params: {action: 'edit', id: id}
%>

And add this method to your controller:

def edit_respond_to_html
if loading_embedded?
render :action => 'update', :layout => false
else
super
end
end
Reply all
Reply to author
Forward
0 new messages