2012-08-23 27 views
1
对象

编辑:缩小误差下来时,我试图通过回形针上传图片缺少参数创建/更新与上传图片

好吧,所以才试图添加我的数据库/编辑元素为不超过上heroku并开始犯错误。经过Heroku的日志得到这个

2012-08-23T19:10:42+00:00 app[web.1]: Completed 500 Internal Server Error in 363ms 
2012-08-23T19:10:42+00:00 app[web.1]: 
2012-08-23T19:10:42+00:00 app[web.1]: NoMethodError (undefined method `[]' for nil:NilClass): 
2012-08-23T19:10:42+00:00 app[web.1]: app/controllers/apartments_controller.rb:68:in `new' 
2012-08-23T19:10:42+00:00 app[web.1]: app/controllers/apartments_controller.rb:68:in `create' 

如果我检查什么的容易控制我得到这个线68 ...

def create 
@apartment = Apartment.new(params[:apartment]) 

真的不知道为什么这开始引起错误的工作一直都很大直到有点前,如果有人可能能够帮助itd不胜感激。



新视角:

<div id="new"><center><h1>New apartment</h1> 
<%= render 'form' %> 
<br /> 
<%= link_to 'Back', apartments_path %></center> 
</div> 



_form查看:

<div id="formApt"> 
<%= form_for @apartment, :html => { :multipart => true } do |f| %> 
    <% if @apartment.errors.any? %> 
<div id="error_explanation"> 
    <h2><%= pluralize(@apartment.errors.count, "error") %> prohibited this apartment from being saved:</h2> 
    <ul> 
    <% @apartment.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
</div> 
    <% end %> 
    <div class="field"> 
    <%= f.label :agent %><br /> 
    <%= f.collection_select :agent, Apartment::AGENTS, :to_s, :to_s, 
    :include_blank => true %><br /> 
     </div> 
    <div class="field"> 
    <%= f.label :location %><br /> 
    <%= f.text_field :location %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :availability %><br /> 
    <%= f.collection_select :availability, Apartment::AVAILSEL, :to_s, :to_s, 
    :include_blank => true %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Bed %><br /> 
    <%= f.number_field :Bed %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Bath %><br /> 
    <%= f.number_field :Bath %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Rent %><br /> 
    <%= f.text_field :Rent %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Pets %><br /> 
    <%= f.collection_select :Pets, Apartment::PETSSEL, :to_s, :to_s, 
    :include_blank => true %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Security_Deposit %><br /> 
    <%= f.text_field :Security_Deposit %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Parking %><br /> 
    <%= f.text_field :Parking %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Laundry %><br /> 
     <%= f.collection_select :Laundy, Apartment::LAUNDRYSEL, :to_s, :to_s, 
    :include_blank => true %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Owner %><br /> 
    <%= f.text_field :Owner %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Date_Avail %><br /> 
    <%= f.date_select :Date_Avail %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Type_Heat %><br /> 
    <%= f.collection_select :Type_Heat, Apartment::HEATSEL, :to_s, :to_s, 
    :include_blank => true %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :AC %><br /> 
    <%= f.collection_select :AC, Apartment::ACSEL, :to_s, :to_s, 
    :include_blank => true %><br /> 
    </div><br /> 
    <div class="field"> 
    <%= f.file_field :photo %><br /> 
    <%= f.file_field :photo2 %><br /> 
    <%= f.file_field :photo3 %><br /> 
     <%= f.file_field :photo4 %><br /> 
    </div> 
    <div class="field"> 
    <%= f.label :Description %><br /> 
    <%= text_area "apartment", "description", "cols" => 60, "rows" => 10 %><br /> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
    <div class="field"> 
    <% f.fields_for :apartment_image do |apartment| %> 
    <% if apartment.object.new_record? %> 
    <p> 
    <%= apartment.label :caption, "Image Caption" %> 
    <%= apartment.text_field :caption %> 
    </p> 
    <p> 
<% end %> 
    </p> 
    </div> 
    <% end %><% end %> 
</div> 



显示视图

<head> 
<!-- First, add jQuery (and jQuery UI if using custom easing or animation --> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> 
    <%= javascript_include_tag "jquery.timers-1.2" %> 
    <%= javascript_include_tag "jquery.easing.1.3" %> 
    <%= javascript_include_tag "jquery.galleryview-3.0-dev" %> 
<%= stylesheet_link_tag "jquery.galleryview-3.0-dev", :media => "all" %> 
<!-- Lastly, call the galleryView() function on your unordered list(s) --> 
<script type="text/javascript"> 
    $(function(){ 
     $('#myGallery').galleryView({ 
    transition_speed: 2000,   //INT - duration of panel/frame transition (in milliseconds) 
    transition_interval: 4000,  //INT - delay between panel/frame transitions (in milliseconds) 
    easing: 'swing',    //STRING - easing method to use for animations (jQuery provides 'swing' or 'linear', more available with jQuery UI or Easing plugin) 
    show_panels: true,    //BOOLEAN - flag to show or hide panel portion of gallery 
    show_panel_nav: false,   //BOOLEAN - flag to show or hide panel navigation buttons 
    enable_overlays: true,   //BOOLEAN - flag to show or hide panel overlays 

    panel_width: 900,    //INT - width of gallery panel (in pixels) 
    panel_height: 500,    //INT - height of gallery panel (in pixels) 
    panel_animation: 'slide',  //STRING - animation method for panel transitions (crossfade,fade,slide,none) 
    panel_scale: 'crop',   //STRING - cropping option for panel images (crop = scale image and fit to aspect ratio determined by panel_width and panel_height, fit = scale image and preserve original aspect ratio) 
    overlay_position: 'bottom',  //STRING - position of panel overlay (bottom, top) 
    pan_images: true,    //BOOLEAN - flag to allow user to grab/drag oversized images within gallery 
    pan_style: 'drag',    //STRING - panning method (drag = user clicks and drags image to pan, track = image automatically pans based on mouse position 
    pan_smoothness: 15,    //INT - determines smoothness of tracking pan animation (higher number = smoother) 
    start_frame: 1,     //INT - index of panel/frame to show first when gallery loads 
    show_filmstrip: true,   //BOOLEAN - flag to show or hide filmstrip portion of gallery 
    show_filmstrip_nav: true,  //BOOLEAN - flag indicating whether to display navigation buttons 
    enable_slideshow: false,   //BOOLEAN - flag indicating whether to display slideshow play/pause button 
    autoplay: false,    //BOOLEAN - flag to start slideshow on gallery load 
    show_captions: true,   //BOOLEAN - flag to show or hide frame captions 
    filmstrip_size: 3,    //INT - number of frames to show in filmstrip-only gallery 
    filmstrip_style: 'scroll',  //STRING - type of filmstrip to use (scroll = display one line of frames, scroll filmstrip if necessary, showall = display multiple rows of frames if necessary) 
    filmstrip_position: 'bottom', //STRING - position of filmstrip within gallery (bottom, top, left, right) 
    frame_width: 164,    //INT - width of filmstrip frames (in pixels) 
    frame_height: 80,    //INT - width of filmstrip frames (in pixels) 
    frame_opacity: 0.5,    //FLOAT - transparency of non-active frames (1.0 = opaque, 0.0 = transparent) 
    frame_scale: 'crop',   //STRING - cropping option for filmstrip images (same as above) 
    frame_gap: 5,     //INT - spacing between frames within filmstrip (in pixels) 
    show_infobar: true,    //BOOLEAN - flag to show or hide infobar 
    infobar_opacity: 1    //FLOAT - transparency for info bar 
    }); 
}); 
</script> 
<style type="text/css"> 
    body { 
     margin: 2em; 
     font-family: Arial, Helvetica, sans-serif; 
} 
</style> 
</head> 
<body> 
<div id="new"><br /><br /><br /><br /><br /><br /><br /><br /> 
<br /><br /> 
    <ul id="myGallery"> 
     <li> <%= image_tag @apartment.photo.url (:large) %> 
     <li> <%= image_tag @apartment.photo2.url (:large) %> 
     <li> <%= image_tag @apartment.photo3.url (:large) %> 
     <li> <%= image_tag @apartment.photo4.url (:large) %> 
</ul> 
    <p> 
    <b>Agent:</b> 
    <%= @apartment.agent %> 
</p> 
<p> 
    <b>Location:</b> 
    <%= @apartment.location %> 
</p> 
<p> 
    <b>Availability:</b> 
    <%= @apartment.availability %> 
</p> 
<p> 
    <b>Bed:</b> 
    <%= @apartment.Bed %> 
</p> 
<p> 
    <b>Bath:</b> 
    <%= @apartment.Bath %> 
</p> 
<p> 
    <b>Rent:</b> 
    $<%= @apartment.Rent %> 
</p> 
<p> 
    <b>Pets:</b> 
    <%= @apartment.Pets %> 
</p> 
<p> 
    <b>Security deposit:</b> 
    $<%= @apartment.Security_Deposit %> 
</p> 
<p> 
    <b>Parking:</b> 
    <%= @apartment.Parking %> 
</p> 
<p> 
    <b>Laundy:</b> 
    <%= @apartment.Laundy %> 
</p> 
<p> 
    <b>Owner:</b> 
    <%= @apartment.Owner %> 
</p> 
    <p> 
    <b>Date avail:</b> 
    <%= @apartment.Date_Avail %> 
</p> 
<p> 
    <b>Type heat:</b> 
    <%= @apartment.Type_Heat %> 
</p> 
<p> 
    <b>Ac:</b> 
    <%= @apartment.AC %> 
</p> 
<p> 
    <b>Description:</b> 
    <%= @apartment.description %> 
</p> 

<center> 
<nav2> 

<span id="home2"> <%= link_to image_tag("home.png"), root_url %></span> 
    <span id="apartments2"><%= link_to image_tag("apartments.png"), {:action =>'aptMenu', :controller => 'apartments'} %></span> 
    <a href="http://livewellchicago.herokuapp.com/?cat=forms"> <%= image_tag("forms.png") %>   </a> 
    <a href="http://livewellchicago.herokuapp.com/?cat=landlords"> 
    <%= image_tag("landlords.png")%> </a> 
    <a href="http://livewellchicago.herokuapp.com/?cat=contactUs"> 
    <%= image_tag("contactus.png") %> </a> 


</nav2> 
</div> 
</body> 

PARAMS:

{"commit"=>"Create Apartment", 
"apartment"=>{"Laundy"=>"In Building", 
"availability"=>"RENTED", 
"Owner"=>"mike", 
"Date_Avail(1i)"=>"2012", 
"Date_Avail(2i)"=>"8", 
"agent"=>"Jason Gold", 
"Security_Deposit"=>"1200", 
"Date_Avail(3i)"=>"23", 
"Rent"=>"3232", 
"Bed"=>"3232", 
"Type_Heat"=>"Radiator", 
"location"=>"ewew", 
"Bath"=>"32323", 
"Pets"=>"Cats Only", 
"Parking"=>"no", 
"AC"=>"Window Unit", 
"photo"=>#<ActionDispatch::Http::UploadedFile:0x103e34c80 @content_type="image/jpeg", 
@tempfile=#<File:/var/folders/bg/dnbp4t6s12g5bh3_yrj6ntvr0000gn/T/RackMultipart20120823-62841-rogrlw-0>, 
@headers="Content-Disposition: form-data; name=\"apartment[photo]\"; filename=\"livingroom.jpg\"\r\nContent-Type: image/jpeg\r\n", 
@original_filename="livingroom.jpg">, 
"description"=>"description goes here"}, 
"authenticity_token"=>"3KhQ0Bh3D+DZSTbPPPhWmgJLqTQ7HyOx45Coa23N4mI=", 
"utf8"=>"✓"} 
+0

顺便说一句,错误是指示'params [:apartment]'是零 – prusswan

+0

嗨prusswan抱歉,标题是从我上一篇文章中意外取出的,我忘了更改它,这是我的错误。然而,我的问题只是与params [:apartment]无关。我试图了解,即使我最近没有碰到控制器,而且它在不久之前还在工作,那么这种情况究竟会如何发生,无处不在。如果您可能有任何想法背后的原因或解决方案itd将不胜感激,并再次抱歉最初的标题混淆 – sonobenissimo

+0

您仍然需要发布与新/创建操作相关的视图,看看是什么不适用于参数 – prusswan

回答

1

好吧,基本上这是我自己的错。曾与公寓模型和has_attached_file声明的格式

has_attached_file :photo, :styles => {:small => "150x150>", :large => "800x720>", :convert_options => { :all =>  '-auto-orient' }} 

Essentually该做的事:convert_options部分是造成帕拉姆的图像是零它被添加到数据库防止任何东西(除非你避免增加图片)。但是,感谢Prusswan的帮助!

0
<%= text_area "apartment" ... %> 

大概应该是:

<%= f.text_area ... %> 

编辑:这两个版本是等价的实际上是基于this,所以问题是其他地方。

+0

这样做会导致一个 '引发ArgumentError在公寓#新的' 错误的参数数目(3 2) 提取的源(围绕线#87): 84: 85:

86: <%= f.label :Description %>
87: <%= f.text_area "apartment", "description", "cols" => 60, "rows" => 10 %>
88:
89: 90:< div class =“actions”> – sonobenissimo

+0

对不起,格式不好,不知道如何在注释中格式化代码 – sonobenissimo

+0

你可以在本地测试并发布当前发送给控制器的参数吗? (有或没有建议的改变) – prusswan