Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS action rendered with layout using slim templates #462

Open
Achillefs opened this issue Dec 19, 2015 · 9 comments
Open

JS action rendered with layout using slim templates #462

Achillefs opened this issue Dec 19, 2015 · 9 comments

Comments

@Achillefs
Copy link

Hi, I am getting an error similar to #384. While using inline update forms, if I hit "Save" the action is performed successfully but an error is displayed and the form doesn't close. Same thing happens when viewing a nested list: click the "close" button does not close the list and produces an error.

No actual javascript errors that I can see in the console, and the action responses are 200s.
The actions return full HTML that includes the layout which seems wrong but I don't know enough about AS to tell.

Using:
active_scaffold (3.4.30)
rails (4.2.4)
ruby 2.1.5p273

Here's an example response from an update action (sorry for the crappy formatting):

<!DOCTYPE html><html><head><title > IntelligentHome.Today < /title><link rel="stylesheet" media="all" href="/assets / admin.css" data-turbolinks-track="true" /><meta name="csrf - param" content="authenticity_token" />
< meta name = "csrf-token" content = "[snip]" /><link href = "https://fonts.googleapis.com/icon?family=Material+Icons" rel = "stylesheet" /><meta content = "width=device-width, initial-scale=1.0" name = "viewport" /></head><body><div class="nav-fixed"><nav><div class="nav-wrapper"><a class="brand-logo" href="#">IHT Admin</a><a class = "button-collapse" data - activates = "mobile-main" href = "#"><i class = "material-icons" > menu < /i></a><ul class = "right hide-on-med-and-down" id = "nav-mobile"><li class = ""><a href = "/admin/users" > Users < /a></li><li class = ""><a href = "/admin/homes" > Homes < /a></li><li class = ""><a href = "/admin/page_categories" > Page Categories < /a></li><li class = ""><a href = "/admin/pages" > Pages < /a></li><li class = ""><a href = "/admin/settings" > Settings < /a></li></ul><ul class="side-nav" id="mobile-main"><li class=""><a href="/admin / users">Users</a></li><li class=""><a href=" / admin / homes">Homes</a></li><li class=""><a href=" / admin / page_categories">Page Categories</a></li><li class=""><a href=" / admin / pages">Pages</a></li><li class=""><a href=" / admin / settings">Settings</a></li></ul></div></nav></div><main class="container">try {
 var action_link = ActiveScaffold.find_action_link('as_admin__users-3-admin__homes-update-1-form');
 action_link.update_flash_messages('');
 action_link.close('<tr class=\"record  \" id=\"as_admin__users-3-admin__homes-list-1-row\" data-refresh=\"1\">\n\n    <td class=\"id-column sorted numeric  \">\n      1\n<\/td>\n    <td class=\"status-column numeric  \">\n      draft\n<\/td>\n    <td class=\"type-column numeric  \">\n      house\n<\/td>\n        <td class=\"floors-column  \">\n      2\n<\/td>\n    <td class=\"rooms-column  \">\n      <a class=\"index as_action toggle\" data-position=\"after\" data-action=\"index\" data-cancel-refresh=\"true\" id=\"as_admin__users-3-admin__homes-__admin__rooms-index-rooms-1-link\" data-remote=\"true\" href=\"/admin/rooms?association=rooms&amp;home_id=1&amp;parent_scaffold=admin%2Fhomes&amp;utf8=%E2%9C%93\">8 rooms<\/a>\n<\/td>\n    <td class=\"created_at-column  \">\n      23 Nov 2015\n<\/td>    \n  <td class=\"actions\"><table>\n    <tr>\n      <td class=\"indicator-container\">\n        <img style=\"visibility:hidden;\" id=\"as_admin__users-3-admin__homes-record-1-loading-indicator\" alt=\"loading indicator\" class=\"loading-indicator\" src=\"/assets/active_scaffold/indicator-07b202d8027099d3add8213095a203cecb4938acdebc80f755ef2251a1a5b880.gif\" />\n      <\/td>\n      <td><a target=\"iht.view_plan\" class=\"view_plan\" id=\"as_admin__users-3-admin__homes-view_plan-1-link\" href=\"/admin/homes/1/view_plan?user_id=3&amp;utf8=%E2%9C%93&amp;association=homes&amp;parent_scaffold=admin%2Fusers&amp;user_id=3\">View Plan<\/a><\/td><td><a class=\"edit as_action\" data-position=\"replace\" data-action=\"edit\" id=\"as_admin__users-3-admin__homes-edit-1-link\" data-remote=\"true\" href=\"/admin/homes/1/edit?user_id=3&amp;utf8=%E2%9C%93&amp;association=homes&amp;parent_scaffold=admin%2Fusers&amp;user_id=3\">Edit<\/a><\/td><td><a class=\"destroy as_action\" data-confirm=\"Are you sure you want to delete My Home?\" data-action=\"destroy\" id=\"as_admin__users-3-admin__homes-destroy-1-link\" data-remote=\"true\" rel=\"nofollow\" data-method=\"delete\" href=\"/admin/homes/1?destroy_action=true&amp;user_id=3&amp;utf8=%E2%9C%93&amp;association=homes&amp;parent_scaffold=admin%2Fusers&amp;user_id=3\">Delete<\/a><\/td>\n    <\/tr>\n  <\/table><\/td>\n<\/tr>\n');

} catch (e) {
alert('RJS error:\n\n' + e.toString());
}
< /main><footer class="page-footer"></footer><script src=" / assets / admin.js" data-turbolinks-track="true"></script></body></html>
@scambra
Copy link
Member

scambra commented Dec 21, 2015

response seems wrong, seeing this response it seems like response should be only js.

Do you have a layout with js.erb extension? Have you overrided some in the controller which can affect this? Have you set layout in the controller or ApplicationController? Just trying to understand what's going on

@Achillefs
Copy link
Author

Hey, no overrides made, just namespaced controllers with active_scaffold :model do |config| blocks.
All controllers inherit from AdminController which sets a layout, But I shouldn't think that is an issue, right? Here's an example controller:

class Admin::HomesController < AdminController
  active_scaffold :home do |c|
    c.list.columns = [ :id, :user, :status, :type, :floors, :rooms, :created_at ]
    c.update.columns = [ :name, :status, :type ]
    c.create.link = false
    c.show.link = false
    c.columns[:floors].clear_link
    c.columns[:type].form_ui = :select
    c.columns[:type].options = { options: Home.types.keys }
    c.columns[:status].form_ui = :select
    c.columns[:status].options = { options: Home.statuses.keys }
    c.action_links.add :view_plan, type: :member, method: :get, page: true
  end

  def view_plan
    home = Home.find(params[:id])
    redirect_to edit_home_path(home)
  end
end

@scambra
Copy link
Member

scambra commented Dec 29, 2015

It shouldn't be an issue, but how is the layout set on admin controller?
And what's the request log? You can post full log for request if not too long, although I'm interested on first lines, where request path and controller, action and format are displayed, and rendered views lines.

@Achillefs
Copy link
Author

The layout is set using layout 'admin' on a parent AdminController. All AS enabled controllers inherit from AdminController.

Here is the log from a request that errors:

  I, [2016-01-12T17:06:36.480950 #3225]  INFO -- :   Rendered /[snip]/active_scaffold-3.4.31/app/views/active_scaffold_overrides/_list_record.html.erb (4.2ms)
  I, [2016-01-12T17:06:36.481631 #3225]  INFO -- :   Rendered /[snip]/active_scaffold-3.4.31/app/views/active_scaffold_overrides/_update_calculations.js.erb (0.3ms)
  I, [2016-01-12T17:06:36.481775 #3225]  INFO -- :   Rendered /[snip]/active_scaffold-3.4.31/app/views/active_scaffold_overrides/row.js.erb within layouts/admin (5.3ms)
  I, [2016-01-12T17:06:36.483269 #3225]  INFO -- : Completed 200 OK in 18ms (Views: 7.1ms | ActiveRecord: 4.4ms)

@scambra
Copy link
Member

scambra commented Jan 13, 2016

What are firsts lines of request? I mean the lines where you can see controller, action and format requested.

Started GET "/admin/homes/..." for IP at TIME
Processing by Admin::HomesController#update as FORMAT

Also, what's name of layout? admin.html.erb? admin.js.erb?

@Achillefs
Copy link
Author

Started GET "/admin/addons/4/list" for ::1 at 2016-01-19 22:37:16 +0100
Processing by Admin::AddonsController#index as JS

The layout name is admin.slim. I tried renaming it to admin.html.slim just to be more explicit but no joy.

@scambra
Copy link
Member

scambra commented Feb 3, 2016

I will try to reproduce this using slim templates

@Achillefs
Copy link
Author

Just so you know, setting layout false, except: [:index] on the parent controller seems to have sorted out some of the issues. Of course that leads to code duplication and is not an ideal solution, but it sort of works.

@scambra
Copy link
Member

scambra commented Feb 6, 2016

What slim related gems are you using? I made a test app, with rails 4.2.5, and only added slim, save works.

@scambra scambra changed the title Getting Request Failed for successful actions JS action rendered with layout using slim templates May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants