Creating an "Edit' link back to AS edit form (JS, not HTML)

6 views
Skip to first unread message

Dennis Bulgatz

unread,
Mar 23, 2023, 11:55:18 AM3/23/23
to ActiveScaffold : Ruby on Rails Gem
Hi Sergio,

I have created a custom show template, and would like to provide a link on the show template to edit the record.

I am using TinyMCE, so for the edit link to work properly, it must be "processed as JS"

Using the "Edit Action" from a list view
Started GET "/sub_tdns/6/edit?adapter=_list_inline_adapter" for ::1 at 2023-03-23 10:47:58 -0500
Processing by SubTdnsController#edit as JS


Using a link from a helper:  link_to "Edit SubTDN", edit_sub_tdn_path(adapter: '_list_inline_adapter')N, class: "button"
Started GET "/sub_tdns/5/edit?adapter=_list_inline_adapter" for ::1 at 2023-03-23 10:48:50 -0500
Processing by SubTdnsController#edit as HTML

Possible to use a link_to helper and get the same edit "form" (using JS and TinyMCE working) that the "edit" button in the list view renders?

Assume it might be needed to do this with a custom action in the controller?  If so, what would that look like?

Thanks!

Dennis

Sergio Cambra

unread,
Mar 24, 2023, 4:45:22 AM3/24/23
to ActiveScaffold : Ruby on Rails Gem, Dennis Bulgatz
Hi Dennis

ActiveScaffold has a setting to show all the actions (same actions displayed in
the row) on the show action, when open on a page, not inline. It's the partial
_show_actions.html.erb, called in show.html.erb. There is a helper method that
you can override to control what links are displayed, display_link_in_show?
(link, position). You can check it to see how it works, but you can't use it
in your custom view, as it renders the links to load as HTML, not as JS.

You could be just get the link from active_scaffold_config.action_links, and
render it with render_action_link(link, record, :authorized => true). If you
want to check if link is authorized, you can use action_link_authorized?(link,
record)[0].

Regards

Dennis Bulgatz

unread,
Apr 2, 2023, 12:33:20 AM4/2/23
to Sergio Cambra, ActiveScaffold : Ruby on Rails Gem

HI Sergio,

 

I was not able to understand what you meant below.

 

In my view, I currently have this call to render a show HTML link:

<%= link_to "(Edit SubTDN)", edit_sub_tdn_path(adapter: '_list_inline_adapter'), class: "button" %>

 

Not sure what object I’d pass for a link in render_action_link(link, record, :authorized => true). 

 

I could not find the API call “display_link_in_show?” you mentioned.  Could you possibly send a git link?  I was looking here.

 

As an aside, do you have a “demo” AS application you use for testing that has many of the controller config options in use, and helpers etc.?

 

Thanks

 

Dennis

Sergio Cambra

unread,
Apr 3, 2023, 6:59:22 AM4/3/23
to ActiveScaffold : Ruby on Rails Gem, Dennis Bulgatz
Hi Dennis

You should be able to get the edit link from active_scaffold_config:

active_scaffold_config.action_links[:edit]

And the record should be in @record variable.

Then you can add to your view:

<%= render_action_link(active_scaffold_config.action_links[:edit], @record,
authorized: true) %>

It will work if you opened the show action with JS, below the row on the table
list. If you opened the show action with the page: true setting in show
action_link, or clicking open in new path, I think the JS won't work to
display the row, as I think it looks for the row.

Other way would be mimic the html generated by the AS helper,
render_action_link:
<%= link_to "(Edit SubTDN)", edit_sub_tdn_path(adapter:
'_list_inline_adapter'), class: "button as_action", data: {position: :after},
remote: true %>

Regards


El domingo, 2 de abril de 2023 6:33:16 (CEST) Dennis Bulgatz escribió:
> HI Sergio,
>
> I was not able to understand what you meant below.
>
> In my view, I currently have this call to render a show HTML link:
> <%= link_to "(Edit SubTDN)", edit_sub_tdn_path(adapter:
> '_list_inline_adapter'), class: "button" %>
>
> Not sure what object I’d pass for a link in render_action_link(link, record,
> :authorized => true).
>
> I could not find the API call “display_link_in_show?” you mentioned. Could
> you possibly send a git link? I was looking
> here<https://www.rubydoc.info/gems/active_scaffold_san/ActiveScaffold/Helpe
> rs/ViewHelpers#get_action_link_id-instance_method>.
Reply all
Reply to author
Forward
0 new messages