Extract Partial

Doesn't look like the "extract partial" refactoring reliably works.

I have the following code snippet, and it fails to extract with the message "Cannot perform refactoring. Selection does not form a fragment for refactoring."

            <% form_remote_tag(:url => {:controller => 'guest_questions', :action => 'create'},
                               :loading => "Element.show('spinner')",
                               :complete => "Element.hide('spinner')") do %>

                <%= text_field :guest_question,
                               :response,
                               :value => "Response here..",
                               :size => 160,
                               :maxlength => 160, :class => 'left' %>
                <div >

                </div>

                <div >
                  <big>
                     
                    <%= submit_tag "Submit", :class => "margin_t_10 margin_l_5" %>
                  </big>
                </div>

            <% end %>

0
6 comments
Avatar
Permanently deleted user

Could you please mark the selection in your code?

0
Avatar
Permanently deleted user

I'm sorry, here's the full view code with the partial selected code highlighted.


<div id="ask_question">

  <div id="question">
    <h1><%= @question.question if !@question.nil? %></h1>
  </div>

  <div ></div>

  <div id="question_answers">
    <% if !@question.nil? %>
        <% if !@question.profile_question_options.nil? && @question.profile_question_options.size == 0 %>

            <% form_remote_tag(:url => {:controller => 'guest_questions', :action => 'create'},
                               :loading => "Element.show('spinner')",
                               :complete => "Element.hide('spinner')") do %>

                <%= text_field :guest_question,
                               :response,
                               :value => "Response here..",
                               :size => 160,
                               :maxlength => 160, :class => 'left' %>
                <div >

                </div>

                <div >
                  <big>
                     
                    <%= submit_tag "Submit", :class => "margin_t_10 margin_l_5" %>
                  </big>
                </div>

            <% end %>


        <% else %>
            <% @question.profile_question_options.each do |option| %>

                <big >
                  <button onclick="<%= remote_function(:url => {:action => 'create', :controller => 'guest_questions', :question_answer_option => option.id }, :loading => "Element.show('spinner')", :complete => "Element.hide('spinner')") %>">
                      <span>
                        <%= option.option.capitalize %>
                      </span>
                  </button>
                </big>

            <% end %>

            <div ></div>

        <% end %>
    <% end %>
    
    <!--
    <span id="question_timer">
      Next question in 15
    </span>
    -->

  </div>

  <div >
    <%= link_to_remote "Skip Question",
                       :url => {:controller => 'guest_questions', :action => 'create' },
                       :loading => "Element.show('spinner')",
                       :complete => "Element.hide('spinner')" %>

    <%= image_tag("spinner.gif", :border=> 0, :id=>"spinner", :style=>"display: none;" ) %>

  </div>

  <div ></div>

</div>

0
Avatar
Permanently deleted user

Hi Jim,

Extract partial refactoring doesn't works with erb fragments yet, we have an issue for this: http://youtrack.jetbrains.net/issue/RUBY-5213
Feel free to vote and track progress of it.

Regards,
Oleg

0

Hi Oleg,

If I correctly understood, "Selection does not form a fragment for refactoring." message appears when any "<% ..." element is founded is selection.

I supose full implementation of refactoring logic could be quite expensive, but maybe divide task into two steps/subtasks will be reasonable.
First step could be a simple disable "Selection does not ..." check, the second one full implementation of refactor logic.

Will be nice, if refactor mechanizm always allows user to move code to partial with some optional warnings.

Regards,
Radek

0
Avatar
Permanently deleted user

I also ran into this issue when trying to extract a partial surrounded by

<% form_for(@risk) do |f| %>
    ...
    ...
<% end %>


as a work-around, I surrounded that form with a <div> and added that to my selected code to extract.  It extracted perfectly after that.  Hope that helps someone.


Trish

0

Awsome walk-around. Thank you very much!

0

Please sign in to leave a comment.