0

这将是一个很难提供意见的问题,所以我会尽可能详细地提供。以下是我试图弄清楚的确切问题。出于某种原因,当我保存时,经验是删除列中的所有其他值并在更新当天写入。我刚刚保存了所有其他值,但为了清楚起见,我将它们排除在表之外。最奇怪的部分是预算和经验设置完全相同,但不幸的是并没有节省相同的费用。下面是关于这个问题的更多细节。

非常感谢您对可能发生的事情的任何见解。

+------+--------+-----------+------------+-----------------+
| id   | bar_id | day       | budget     | experience      |
+------+--------+-----------+------------+-----------------+
| 1816 |    369 | monday    | LOW BUDGET |                 |
| 1817 |    369 | tuesday   | low budget |                 |
| 1818 |    369 | wednesday | low budget | IN CONVERSATION |
| 1819 |    369 | thursday  | low budget |                 |
| 1820 |    369 | friday    | low budget |                 |
| 1821 |    369 | saturday  | low budget |                 |
+------+--------+-----------+------------+-----------------+

+------+--------+-----------+------------+--------------------+
| id   | bar_id | day       | budget     | experience         |
+------+--------+-----------+------------+--------------------+
| 1822 |    369 | monday    | LOW BUDGET |                    |
| 1823 |    369 | tuesday   | low budget |                    |
| 1824 |    369 | wednesday | low budget |                    |
| 1825 |    369 | thursday  | low budget | ON THE DANCE FLOOR |
| 1826 |    369 | friday    | low budget |                    |
| 1827 |    369 | saturday  | low budget |                    |
+------+--------+-----------+------------+--------------------+

这些是表单(视图)的输入

    <div class="row clearfix">
      <div class="label">Budget</div>
        <div class="mid budget">
        <div class="mid">
          <input class="venProfileInputs caps" name="bar_profile[<%= day %>][budget]" onblur=checkBudVals(this)>
        </div>
      </div>
    </div>

    <div class="row clearfix">
      <div class="label">Experience</div>
        <div class=" mid">
          <input class="venProfileInputs caps" name="bar_profile[<%= day %>][experience]" onblur=checkExVals(this) /> 
        </div>
      </div>

然后进入控制器

  def update
    @bar = Bar.find(params[:id])
    if @bar.update_attributes(params[:bar])
      @bar.update_profiles(params[:bar_profile])
      redirect_to "/admin", :notice => "Bar was successfully updated."
    else
      render :action => :edit
    end
  end

它在模型中得到更新

  def update_profiles(params)
    profiles.each {|p| p.destroy }
    
    params[:active_profiles].split(',').each do |profile_day|
      next if profile_day.blank?
      
      add_profile(params[profile_day.to_sym])
      
      # sets up crowd tags
      crowd_tags_ids = params[profile_day.to_sym][:tags]
      unless crowd_tags_ids.blank?
        crowd_tags_ids.split(',').each do |tag_id|
          next if tag_id.strip == ""
          profiles.last.crowd_tags << CrowdTag.find(tag_id)
        end
      end      
      profiles.last.set_crowd_tags
      #need to loop through cf_tags_ids = params[profile_day.to_sym][:cf_tags]
      cf_tags_ids = params[profile_day.to_sym][:cf_tags]
      unless cf_tags_ids.blank?
        # loop through each category 0,1,2,3,4
        cf_tags_ids.each_pair{ |cat, ids|
            #cycle through each id in the current cat and add to crowd fiter tag
            ids.split(',').each do |cf_id|
                next if cf_id.strip == ""
                profiles.last.crowd_filter_tags << CrowdFilterTag.find(cf_id)
            end
          }
      end     
      profiles.last.set_cf_tags
      # below is not working for saving experience
      profiles.last.experience = params[profile_day.to_sym][:experience]
      logger.info "#{profiles.last.inspect}"
      #### Still need to save experience some how, budget seems to be getting saved
      # but only one value for experience is being logged in a single row for each bar_id
      

    end
  end

记录器输出:

Parameters: {"utf8"=>"✓&quot;, 
"bar"=>{"name"=>"Rue B", "website"=>"www.ruebnyc.com", "neighbourhood"=>"Greenwich Village",
"street_address"=>"188 Avenue B", "city"=>"New York", "country"=>"US", "state"=>"NY", "zipcode"=>"10009"}, 
"bar_profile"=>{"active_profiles"=>",monday,tuesday,wednesday,thursday,friday,saturday", 

"monday"=>{"day"=>"monday", "description"=>"", "plan_b"=>"", "capacity"=>"100",    
"rating"=>"5", "budget"=>"LOW BUDGET", "experience"=>"ON THE DANCE FLOOR", 
"cf_tags"=>{"0"=>"83,", "1"=>"127,", "2"=>"120,", "3"=>"111,", "4"=>"128,"}, "tags"=>"16,46,45,"}, 

"tuesday"=>{"day"=>"tuesday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"61,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}, 

"wednesday"=>{"day"=>"wednesday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.", 
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"61,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}, 

"thursday"=>{"day"=>"thursday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.", 
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"59,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}, 

"friday"=>{"day"=>"friday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.", 
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"60,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}, 

"saturday"=>{"day"=>"saturday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"59,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}, 

"sunday"=>{"day"=>"sunday", "description"=>"", "plan_b"=>"", "capacity"=>"", "rating"=>"",
"budget"=>"", "experience"=>"", "cf_tags"=>{"0"=>"", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}}, "id"=>"369"}
4

2 回答 2

0

我无法想象这真的对任何人有帮助,但是这个巨大项目中的某些 JQuery 依赖于 html 中的特定设置。“体验”块缺少一个额外的 div,它允许 JS 获取正确的值……这就是为什么它不断更新为 nil,因为找不到该值。

        <div class="row clearfix">
          <div class="label">Budget</div>
          <div class="mid budget">
          <div class="mid">
            <input class="venProfileInputs caps" name="bar_profile[<%= day %>][budget]" onblur=checkBudVals(this)>
            </div>
          </div>
        </div>

        <div class="row clearfix">
          <div class="label">Experience</div>
------>   <div class="mid experience">
          <div class=" mid">
            <input class="venProfileInputs caps" name="bar_profile[<%= day %>][experience]" onblur=checkExVals(this) /> 
          </div>
          </div>
        </div>
于 2012-11-20T20:08:40.467 回答
0

据我所知,它正在做它应该做的事情。您的日志文件显示,除了“星期一”之外的每一“天”,“体验”都设置为“”。星期一它被设置为“在舞池上”。其中,“预算”设置为每天的某事。

我会查看您的 HTML/JS,看看您是否在提交表单之前以某种方式清除了该字段。

于 2012-11-20T19:23:32.303 回答