0
votes

I have a table in my database and I'm showing in a page.

The problem happens when I am saving the changes.

I need the Rails process using js and not redirect the user to another page when you click save.

So far, I can save changes but I am always redirected to other pages processed by HTML instead JS.

controller:

filter_resource_access :nested_in => :releases
filter_resource_access :nested_in => :project

respond_to :js, only: [:update, :edit, :show]
respond_to :html

before_filter :load_issue, :load_project, :load_release

def edit
end

def update
  if @issue_value.update_attributes(params[:issue_value])
    flash.now[:notice] = t('messages.successfully_updated_entity.f',
                                             :entity => IssueValue.model_name.human)
    respond_to do |format|
      format.js
    end
  end
end

_issue_values_table:

<table class="zebra-striped">

 <thead>
 <tr>
   <th><%= IssueValue.human_attribute_name :name %></th>
   <th><%= IssueValue.human_attribute_name :value %></th>
   <th><%= IssueValue.human_attribute_name :client_value %></th>
   <th></th>
</tr>
</thead>
<tbody>
<% @issue_types = IssueType %>
<% for issue_value in @release.issue_values.order("issue_type_id") %>
  <%= content_tag_for :tr, issue_value, :class => "clickable" do %>
    <td width="42%"><%#= t(@issue_types.find(issue_value.issue_type_id).label_key) %></td>
    <td width="20%">
      <%= number_to_currency issue_value.value %>
    </td>
    <td width="20%">
      <%= number_to_currency issue_value.client_value %>
    </td>
    <td width="12%" class="icons right">
      <%= edit_icon issue_value, [:edit, @project, @release, issue_value], :remote => true, 'data-default-action' => true %>
    </td>
   <% end %>
<% end %>
</tbody>

_form_row:

 <td colspan="4">
   <%= form_for [@project, @release, @issue_value], :remote => true, :html => {:style => "margin:0"} do |f| %>
  <table class="basic">
    <tr>
      <td class="span8 middle">
        <div class="clearfix">
          <%#= f.text_field :name, :placeholder => IssueType.human_attribute_name(:name),
                           :autofocus => true, :class => "span10" %>
        </div>
      </td>
      <td class="span5 middle">
        <div class="clearfix">
          <%= f.text_field :value, :placeholder => IssueValue.human_attribute_name(:value),
                   :autofocus => true, :class => "span2" %>
        </div>
      </td>
      <td class="span5 middle">
        <div class="clearfix">
          <%= f.text_field :client_value, :placeholder => IssueValue.human_attribute_name(:client_value),
                   :class => "span2" %>
        </div>
      </td>
      <td class="span2 icons">
        <%= f.submit t('actions.save'), :disable_with => t('messages.please_wait'), :class => 'btn small', :remote => true %>
      </td>
    </tr>
  </table>
<% end %>

In views/issue_values I have:

  1. edit.js.erb

  2. show.js.erb

  3. update.js.erb

  4. _form_row.html.erb

  5. _issue_values_table.html.erb

Well, I don't undestand why this not works.

The Log is:

Started GET "/projects/pro-/releases/release02/values/14/edit" for 127.0.0.1 at 2013-12-13 08:39:36 -0200 Processing by IssueValuesController#edit as JS Parameters: {"project_id"=>"pro-", "release_id"=>"release02", "id"=>"14"} SQL (0.5ms) SHOW TABLES User Load (0.1ms) SELECT users.* FROM users WHERE ((users.auth_token = 'ji2lt8p1185q6q1l' AND users.status_id = 2)) LIMIT 1 SQL (1.5ms) describe releases_browser_versions SQL (0.6ms) describe releases_os_versions SQL (0.7ms) describe releases_mobile_models Release Load (0.1ms) SELECT releases.* FROM releases WHERE releases.identifier = 'release02' LIMIT 1 IssueValue Load (0.1ms) SELECT issue_values.* FROM issue_values WHERE issue_values.id = 14 LIMIT 1 SQL (0.6ms) SHOW TABLES Project Load (0.1ms) SELECT projects.* FROM projects WHERE projects.identifier = 'pro-' LIMIT 1 CACHE (0.0ms) SELECT issue_values.* FROM issue_values WHERE issue_values.id = 14 LIMIT 1 Rendered issue_values/_form_row.html.erb (34.6ms) Rendered issue_values/edit.js.erb (36.1ms) Completed 200 OK in 642ms (Views: 50.4ms | ActiveRecord: 4.3ms) [2013-12-13 08:39:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

Started POST "/projects/pro-/releases/release02/values/14" for 127.0.0.1 at 2013-12-13 08:39:37 -0200 Processing by IssueValuesController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"vuyP9Jwm4pS63OF7xucBHGo0L5m61ayj3aWcXYpFTKM=", "issue_value"=>{"value"=>"10,00", "client_value"=>"5,00"}, "commit"=>"Salvar", "project_id"=>"pro-", "release_id"=>"release02", "id"=>"14"} SQL (0.5ms) SHOW TABLES User Load (0.1ms) SELECT users.* FROM users WHERE ((users.auth_token = 'ji2lt8p1185q6q1l' AND users.status_id = 2)) LIMIT 1 SQL (0.7ms) describe releases_browser_versions SQL (0.5ms) describe releases_os_versions SQL (0.6ms) describe releases_mobile_models Release Load (0.1ms) SELECT releases.* FROM releases WHERE releases.identifier = 'release02' LIMIT 1 IssueValue Load (0.2ms) SELECT issue_values.* FROM issue_values WHERE issue_values.id = 14 LIMIT 1 SQL (0.5ms) SHOW TABLES Project Load (0.1ms) SELECT projects.* FROM projects WHERE projects.identifier = 'pro-' LIMIT 1 CACHE (0.0ms) SELECT issue_values.* FROM issue_values WHERE issue_values.id = 14 LIMIT 1 SQL (0.1ms) BEGIN SQL (0.1ms) COMMIT Completed 500 Internal Server Error in 784ms

ActionView::MissingTemplate (Missing template issue_values/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:pt, :pt]} in view paths "/var/www/base2_crowdtest/2112/final/trunk/app/views", "/usr/local/rvm/gems/ruby-1.9.3-p448/gems/client_side_validations-3.1.4/app/views", "/usr/local/rvm/gems/ruby-1.9.3-p448/gems/declarative_authorization-0.5.6/app/views", "/usr/local/rvm/gems/ruby-1.9.3-p448/gems/kaminari-0.13.0/app/views"): app/controllers/issue_values_controller.rb:12:in block (3 levels) in update' app/controllers/issue_values_controller.rb:11:inblock in update' app/controllers/issue_values_controller.rb:9:in `update'

Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.8ms)

Someone help me?

1

1 Answers

1
votes

If you don't need a redirect then just remove it. And add respond_to/respond_with to controller. Also you'll need update.js.erb for handling situation when record is successfully saved. Like that:

class IssueValuesController < LoginRequiredController
  respond_to :js, only: [:update]
  respond_to :html
  filter_resource_access :nested_in => :releases 

  def update
    if @issue_value.update_attributes(params[:issue_value])
      flash.now[:notice] = t('messages.successfully_updated_entity.f',
                                                 :entity => IssueValue.model_name.human)
    end
    respond_with(@issue_value)
  end

# rest of the class ommited
end

Workaround:

try changing your form to:

<%= form_for [@project, @release, @issue_value], :remote => true, :html => {:format => "js", :style => "margin:0"} do |f| %>