ruby on rails - Controller works fine locally but not on heroku -


i'm using carrierwave amazon s3 , heroku upload , store images. works fine locally reason controller function "new" isn't being executed on heroku. i've printed params[:controller] & params[:action] view, , both of them correct, i'm not sure problem is.

routes.rb

      rails.application.routes.draw   resources :surroundings    resources :headings    resources :options    resources :categories    resources :mains    resources :properties       resources :images, only: [:index, :new, :create, :destroy]     collection      'update_main'      end      end       'addoption'     post 'postoption'  end  root 'search#main' 'main' =>'search#main' 

images_controller.rb

class imagescontroller < applicationcontroller     def new #redirect_to property_images_path #used trouble shooting - not redirect @property=property.find(params[:property_id]) @image = image.new  end    def index     @images = property.find(params[:property_id]).images   end    def update_main #set current main image false    r=property.find(params[:property_id]).images.where("main" => true).first    r.main=false unless r.nil?    r.save unless r.nil?    @image=image.find(params[:main])    @image.main=true;    @image.save  redirect_to property_images_path, notice: "the image has been uploaded." end     def create     @image = image.new(image_params)     @image.property_id=params[:property_id]     if @image.save       redirect_to property_images_path, notice: "the image has been uploaded."     else       render "new"     end   end    def destroy     @image = image.find(params[:id])     @image.destroy     redirect_to property_images_path, notice:  "the image  has been deleted."   end  private   def image_params    params.require(:image).permit(:attachment,:property_id)   end end 

new.html.erb

<h1>add new image</h1> <%=params[:controller]%> <%=params[:action]%>   <%= form_for([@property,@image]) |f| %>  <%= label_tag("select image file") %>    <%= f.file_field :attachment, class:"btn btn-default" %>   <br>      <%= f.submit class:"btn btn-primary" %>  <% end %> 

heroku error logs

processing imagescontroller#new html 2016-02-06t07:43:25.314010+00:00 app[web.1]:   parameters: {"property_id"=>"1"} 2016-02-06t07:43:25.519196+00:00 heroku[router]: at=info method=get path="/properties/1/images/new" host=auspropguides.herokuapp.com request_id=ecaefc40-5556-4239-9da6-1a154fa489f3 fwd="14.201.25.50" dyno=web.1 connect=0ms service=391ms status=500 bytes=1754 2016-02-06t07:43:25.509640+00:00 app[web.1]:   rendered images/new.html.erb within layouts/application (1.9ms) 2016-02-06t07:43:25.512962+00:00 app[web.1]:  2016-02-06t07:43:25.512964+00:00 app[web.1]: actionview::template::error (first argument in form cannot contain nil or empty): 2016-02-06t07:43:25.509818+00:00 app[web.1]: completed 500 internal server error in 196ms 2016-02-06t07:43:25.512968+00:00 app[web.1]:     7:  <%= label_tag("select image file") %> 2016-02-06t07:43:25.512969+00:00 app[web.1]:     8:    <%= f.file_field :attachment, class:"btn btn-default" %>  2016-02-06t07:43:25.512965+00:00 app[web.1]:     3: <%=params[:action]%> 2016-02-06t07:43:25.512967+00:00 app[web.1]:     5:  2016-02-06t07:43:25.512968+00:00 app[web.1]:     6: <%= form_for([@property,@image]) |f| %> 2016-02-06t07:43:25.512966+00:00 app[web.1]:     4:  2016-02-06t07:43:25.512971+00:00 app[web.1]:   app/views/images/new.html.erb:6:in `_app_views_images_new_html_erb___892626609660663212_69968138740340' 2016-02-06t07:43:25.512972+00:00 app[web.1]:  2016-02-06t07:43:25.512970+00:00 app[web.1]:     9:  2016-02-06t07:43:25.512972+00:00 app[web.1]:  

console log

irb(main):001:0> property.find(1)   property load (2.2ms)  select  "properties".* "properties" "properties"."id" = $1 limit 1  [["id", 1]]   property load (2.2ms)  select  "properties".* "properties" "properties"."id" = $1 limit 1  [["id", 1]] => #<property id: 1, listing_status: "in draft", my_property_reference: "my reference", floor_area: 350, land_area: 500, state: "new development", city: "sydney", area: "cbd", street: "123 fake st", price: 800000, floors: 2, property_type: "apartment", property_age: nil, completion: 2016, bedrooms: 5, bathrooms: 2, under_cover_car_spaces: 3, car_spaces: nil, car_lock_up_garage: 1, additional_information: "great location in great area.", description: "great house great house great house great house gr...", created_at: "2016-02-04 03:44:54", updated_at: "2016-02-04 03:46:55", suburb: nil> irb(main):002:0> image.all   image load (1.8ms)  select "images".* "images"   image load (1.8ms)  select "images".* "images" => #<activerecord::relation []> irb(main):003:0> image => image(id: integer, main: boolean, attachment: string, created_at: datetime, updated_at: datetime, property_id: integer) irb(main):004:0>  

the issue since you've nested images under properties, you'll have declare both @instance variables if want form_for work:

def new   @property = property.find params[:property_id]   @image    = image.new end 

of course, already.

the problem, then, property id of 1 doesn't exist on production environment. need make sure you're handling data-set same care development (evaluating if dependent objects don't exist):

def new    @property = property.find params[:property_id]    if @property        @image = @property.images.new    else      redirect_to root_path, notice: "no property"     end end 

you'll want define multiple resources @ once in routes (to clean up):

#config/routes.rb resources :surroundings, :headings, :options, :categories, :mains resources :properties   resources :images, only: [:index, :new, :create, :destroy]     'update_main', on: :collection   end    :addoption   post :postoption end  resources :search, path: "", only: []   :main, on: :collection end  root 'search#main' 

update

the solution trivial, op left photos_controller.rb file class imagescontroller < applicationcontroller declaration. removing file fixed issue.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -