sql - Couldn't find Project with id=1 [WHERE "projects"."deleted_at" IS NULL] -
i using paranoia gem.
i have bunch of projects in database somereason behaving if deleted. when navigate projects/1 route error:
couldn't find project id=1 [where "projects"."deleted_at" null]
when type in console:
project.find(1).deleted_at
i
nil
what happening here?
this controller show action:
def show @project = project.find(params[:id]) @comments = comment.all.where(:project_id => @project.id) @updates = projectupdate.all.where(:project_id => @project.id) end
error happens on
@project = project.find(params[:id])
here model project scopes:
scope :by_category, lambda {|category| {:conditions => {:category_id => category.id}}} scope :by_npo, lambda {|npo| {:conditions => {:npo_id => npo.id}}}
with project.find(1)
get:
=> #<project id: 1, name: "project 1", npo_id: 1, description: "project1 description", location_id: 4, singular_unit: "1", past_tense_action: "past tense action", conversion: #<bigdecimal:7547d78,'0.1 5e1',18(45)>, created_at: "2014-05-13 00:12:33", updated_at: "2014-05-22 01:20:51", future_tense_act ion: "future tense action", plural_unit: "2", amount1: #<bigdecimal:75475b0,'0.1e2',9(36)>, amount2: #<bigdecimal:7547520,'0.2e2',9(36)>, amount3: #<bigdecimal:7547490,'0.3e2',9(36)>, min_amount: nil, other_amount: true, short_description: "project1 short description", featured_image_id: 3, deleted_ at: nil>
from index page link 2ice(this relevant code:
<div class="pj"> <h5><%= link_to project.name, project, :class => "button-link" %> </h5> <hr /> <div class="index_featured_image"> <%= link_to image_tag(project.get_featured_image, :alt => "project title", class: "featured_image"), project %> </div> <div class="proj-content"> <p><strong><%= link_to project.npo.name, npo_path(project.npo) %></strong></br> <%= project.short_description %></p> </div> <div> <p class="project-loc"><i class="footicons fi-marker large"></i> <%= project.location.city_state %></p> </div> <div class="text-center"> <%= button_tag :type => "button", :class => "radius" %> <%= link_to "view more", project, :class => "button-link" %> <% end %> </div> </div>
couple guesses , advice. first guesses. if project.find(params[:id])
calls where "projects"."deleted_at" null
condition on table, there must default_scope
call on project. though it's still weird why id prevents find method finding correct project, if it's not deleted. let me see default_scope (or better post whole model in gist) , might tell bit more.
now advice. it's not related current issue, believe, make rails life lot easier these days.
try not use deprecated syntax, on new one. e.g. scope calls should
scope :by_category, ->(category){where(category_id: category.id)}
don't use
.all
.where
. don't need it..where
call return activerecord::relation object looking for.try reduce number of instance variables in controllers. example can omit use of
@comments
,@updates
variables inshow
action, provided have set needed associations on project model.has_many :comments has_many :updates, class_name: projectupdate
then in view can refer them @project.comments , @project.updates without need store them separately. clean controller bit. also, if want ensure comments , updates not lazy-loaded, can load them project calling
@project = project.includes(:comments, :updates).find(params[:id])
.
hope helpful. i'll update answer have more concrete on problem.
Comments
Post a Comment