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

Inline links returning HTML and not JS #521

Open
imillar opened this issue Oct 11, 2016 · 4 comments
Open

Inline links returning HTML and not JS #521

imillar opened this issue Oct 11, 2016 · 4 comments

Comments

@imillar
Copy link

imillar commented Oct 11, 2016

Rails 4.2.7.1
Ruby 2.3.1
AS 3.4.41.1

Hoping that someone can help with this -- I've got an inline link for editing on my page, and it is not loading the form properly. I don't know if this is a configuration error on my part, or a bug in the AS code.

config.update.link.label = 'Edit Module'
config.update.link.inline = true

What I can see happening is that the request is going in and being handled by the controller as JS

Started GET "/admin/program_management/program_modules/209/edit?program_module_base_id=210&program_module_type=english" for 127.0.0.1 at 2016-10-11 11:34:08 -0400
Processing by Admin::ProgramManagement::ProgramModulesController#edit as JS

-- but what is returned is JUST HTML, and the AJAX Responders are erroring out because they can't parse what's returned. Any ideas?

Thanks in advance!

@scambra
Copy link
Member

scambra commented Oct 14, 2016

That's right, activescaffold will return html for inline displaying, and activescaffold JS has responders which expect html and add in the right place. Have you added require active_scaffold to your js manifest?

@mlessard
Copy link

Hi,
Firstly, thanks a lot for the response. I've been battling this for a while and I'm stuck.

I do have

//= require active_scaffold

in my application.js, and some parts of AS are working.
I have some nested links on the same page, and they are returning properly, and displaying their forms inline in the page. They're returning JS, in the form of:

ActiveScaffold.replace_html('as_admin__program_management__program_modules-209-admin__program_management__program_module_appendices-content', 'the content');

When I try to interact with the links on the generated form (or the "edit" link on the main page), I get my requests returned with just the html, and no ActiveScaffold.replace() JS wrapping it.

Is there something I can do to change the handler that receives the response? Have it handled by something which isn't expecting JS?

This is an older project which was on Rails 2.3.5 LTS, and is now on Rails 4. The project is using prototype and prototype-ujs. Do you think that they may possibly be interfering?

@scambra
Copy link
Member

scambra commented Oct 17, 2016

Nested links return js code like that (ActiveScaffold.replace_html) but edit links return html and ActiveScaffold listeners will add html to right place. Request success should trigger document.on('ajax:success', 'a.as_action', function(event) which uses action_link.insert(event.memo.request.transport.responseText) to insert html in page.

Are you using jquery and prototype, or just prototype? I don't know if it may be a bug in prototype/active_scaffold.js but edit links always worked like that. You could try to test those links using only jquery, with no prototype. I haven't testing prototype part of ActiveScaffold in years, and I'm thinking in dropping support, because some new features were never added to prototype part, I don't have time to support it and I don't think much people use it.

I know some people use prototype and ActiveScaffold with jquery and jquery_ujs, using jQuery.noConflict, but I don't know if using jquery_ujs and prototype_ujs at same time is supported.

@HarishR-amesh
Copy link

HarishR-amesh commented Mar 13, 2018

I have model Template, which has thumbnail attachment, is uploaded using carrierwave. Im trying to upload image in list page. following https://github.com/activescaffold/active_scaffold/wiki/Adding-custom-actions. form is loaded as 'js' request, but when submit form it goes as 'html' request and params is record => {:thumbnail}, form is not closed and row is refreshed.

Controller:

active_scaffold :template do
            conf.action_links.add :thumbnail, label: 'Change Thumbnail', :type => :member, method: :put, position: :after
 end

def thumbnail
    @record = find_if_allowed(params[:id], :read)
    @column = active_scaffold_config.columns[:thumbnail]
    respond_to_action(:thumbnail)
  end

  def update_thumbnail
    process_action_link_action do |record|
      if record.update_attributes(thumbnail_params)
         self.successful = true
        flash[:info] = ' updated successfully'
      end
    end
  end

_thumbnail.html.erb

<ol class="form">
    <li class="form-element">
        <%= form_attribute(@column, @campaign_template, scope) %>
        <%# for ActiveScaffold 3.2.x %>
        <%#= render :partial => 'form_attribute', :locals => { :column => @column, :scope => scope} %>
    </li>
</ol>

logs:


Started PUT "/admin/campaign_templates/12/thumbnail?_method=put&adapter=_list_inline_adapter" for 127.0.0.1 at 2018-03-13 17:51:00 +0530
Processing by Admin::CampaignTemplatesController#thumbnail as JS
  Parameters: {"adapter"=>"_list_inline_adapter", "id"=>"12"}

  CampaignTemplate Load (1.3ms)  SELECT  `campaign_templates`.* FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12 LIMIT 1
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_form_messages.html.erb (23.1ms)
DEPRECATION WARNING: Relying on @record is deprecated, include :object in options with record. (called from _app_views_admin_campaign_templates__thumbnail_form_html_erb___1016874531010777311_70218353346380 at /Users/harish/Documents/Projects/granville-station-web/app/views/admin/campaign_templates/_thumbnail_form.html.erb:3)
DEPRECATION WARNING: Relying on @record is deprecated, include :object in options with record. (called from _app_views_admin_campaign_templates__thumbnail_form_html_erb___1016874531010777311_70218353346380 at /Users/harish/Documents/Projects/granville-station-web/app/views/admin/campaign_templates/_thumbnail_form.html.erb:3)
DEPRECATION WARNING: Relying on @record is deprecated, include :object in html_options with record. (called from _app_views_admin_campaign_templates__thumbnail_form_html_erb___1016874531010777311_70218353346380 at /Users/harish/Documents/Projects/granville-station-web/app/views/admin/campaign_templates/_thumbnail_form.html.erb:3)
  Rendered admin/campaign_templates/_thumbnail_form.html.erb (43.5ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_base_form.html.erb (146.0ms)
  Rendered admin/campaign_templates/_thumbnail.html.erb (191.0ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_messages.html.erb (1.9ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb (36.6ms)
Completed 200 OK in 354ms (Views: 75.1ms | ActiveRecord: 4.7ms)


Started POST "/admin/campaign_templates/12/update_thumbnail?iframe=true" for 127.0.0.1 at 2018-03-13 17:51:07 +0530
Processing by Admin::CampaignTemplatesController#update_thumbnail as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"oHriVSbJdh9X0XphuX1aY+nQcAT4ycN7gLjMJeoFpTM39L2kGJissOCdcgXO9j1wNjenD7zQB5DMgHIiRoe/AQ==", "record"=>{"thumbnail"=>#<ActionDispatch::Http::UploadedFile:0x00007fb9f948ae80 @tempfile=#<Tempfile:/var/folders/2r/qcspk99511v_tqyvp3wknfq800015j/T/RackMultipart20180313-24068-174ux3r.png>, @original_filename="dummy.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"record[thumbnail]\"; filename=\"dummy.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Update Thumbnail", "iframe"=>"true", "id"=>"12"}
  User Load (1.5ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
  User Load (1.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  CACHE (0.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1  [["id", 1]]
  User Load (1.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 33 LIMIT 1
>>>> CHECKING ADMIN ROLE -- /admin/campaign_templates/12/update_thumbnail -- /admin/pages?blog=true
  CampaignTemplate Load (0.9ms)  SELECT  `campaign_templates`.* FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12 LIMIT 1
  CACHE (0.1ms)  SELECT  `campaign_templates`.* FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12 LIMIT 1  [["id", "12"]]
  CampaignCategory Load (0.8ms)  SELECT `campaign_categories`.* FROM `campaign_categories` WHERE `campaign_categories`.`discarded_at` IS NULL AND `campaign_categories`.`id` IN (15)
   (0.3ms)  BEGIN
  CampaignTemplate Load (1.1ms)  SELECT  `campaign_templates`.* FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12 LIMIT 1
  SQL (0.8ms)  UPDATE `campaign_templates` SET `thumbnail` = 'dummy.png', `updated_at` = '2018-03-13 12:21:08' WHERE `campaign_templates`.`id` = 12
   (1.6ms)  COMMIT
Redirected to http://admin.lvh.me:3000/admin/campaign_templates/12/list
Completed 302 Found in 5769ms (ActiveRecord: 9.2ms)


Started GET "/admin/campaign_templates/12/list" for 127.0.0.1 at 2018-03-13 17:51:13 +0530
Processing by Admin::CampaignTemplatesController#index as HTML
  Parameters: {"id"=>"12"}
  User Load (1.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
  User Load (1.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  CACHE (0.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1  [["id", 1]]
  User Load (1.2ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 33 LIMIT 1
>>>> CHECKING ADMIN ROLE -- /admin/campaign_templates/12/list -- /admin/pages?blog=true
   (0.7ms)  SELECT COUNT(*) FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_header.html.erb (11.7ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_column_headings.html.erb (6.6ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_messages.html.erb (0.3ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_messages.html.erb (28.3ms)
  CampaignTemplate Load (0.8ms)  SELECT  `campaign_templates`.* FROM `campaign_templates` WHERE `campaign_templates`.`discarded_at` IS NULL AND `campaign_templates`.`id` = 12 LIMIT 15 OFFSET 0
  CampaignCategory Load (0.7ms)  SELECT `campaign_categories`.* FROM `campaign_categories` WHERE `campaign_categories`.`discarded_at` IS NULL AND `campaign_categories`.`id` IN (15)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_record.html.erb (17.3ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_pagination.html.erb (0.6ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list.html.erb (167.4ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/_list_with_header.html.erb (223.1ms)
  Rendered /Users/harish/.rvm/gems/ruby-2.3.5/gems/active_scaffold-3.4.28/app/views/active_scaffold_overrides/list.html.erb within layouts/admin (244.0ms)
  Rendered shared/_footer.html.erb (0.1ms)
  Rendered layouts/_intercom.html.erb (14.2ms)
  Rendered layouts/admin.html.erb (759.8ms)
Completed 200 OK in 846ms (Views: 785.7ms | ActiveRecord: 5.5ms)

screen shot 2018-03-13 at 5 53 48 pm

After update just stands as this form, but code inside process action link gets exceuted.

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

4 participants