【问题标题】:Ruby on Rails 3 Partial PagesRuby on Rails 3 部分页面
【发布时间】:2013-11-05 13:48:47
【问题描述】:

对于某个员工,我有一份报告。每个报告都有一些变化。每个班次都可以纠正。我正在从 Ruby 2 迁移到 Ruby 3。我正在处理部分页面。当我点击正确时,会出现一个部分页面,当我点击更新时,页面应该返回到带有该员工 ID 的部分页面详细信息。

_modify_item.html.erb:

<%= form_for :modified_item, :url => {:action => :modify_item, :report_id => @monthly_report.id, :modified_item_id => @modified_item.id,remote: true}  do |form| %>

<table width=100% height=100%>
<td width=150 style='border: 0px; background-color: #eee' align=center>
        <%= form.hidden_field :report_id, :value => @monthly_report.id %>
        <%= submit_tag 'Update', :name => 'update', :value => 'Update', :class => 'highlighted_button' %>

        <%= link_to 'Cancel',
                    {:action => 'details', :report_id => @monthly_report.id},
                    :class => 'highlighted_button',
                    remote: true %>
    </td>
    </tr>
</table>

<% end %>

controller.rb:

def modify_item
        @modified_item = Employee::MonthlyReportItem.find(params[:modified_item_id])
        @monthly_report = @modified_item.report
        begin
            @modified_item.update_attributes!(params[:modified_item])
            flash[:notice] = 'Position was updated.'
            flash[:warning]=@modified_item.verification_problems if !@modified_item.correct? 
            redirect_to('/accounts/salary/details', :report_id => @monthly_report.id) and return
        rescue Exception => e
            flash.now[:error] = "Some of the values are missing or are incorrect. Try again."
        end
        #render(:partial => 'details') and return
    end

modify_item.js.erb:(试过没有成功)

//$("#salary_popup").html("<%= j(render partial: 'details') %>");

更新:忘记提及 if 内部的确切错误

Couldn't find Employee::MonthlyReport without an ID

Rails 进入 details 函数并尝试这样做:

def details
        if params[:item].nil?
            @monthly_report = Employee::MonthlyReport.find(params[:report_id])
        else
            @monthly_report = Employee::MonthlyReport.find(params[:item][:report_id])
        end
..
end

【问题讨论】:

    标签: javascript ruby-on-rails ruby ruby-on-rails-3


    【解决方案1】:

    您创建的隐藏字段是否具有名称属性?如果不尝试添加。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 2012-07-07
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多