Skip to content

Instantly share code, notes, and snippets.

@attatae
Created April 11, 2014 01:41
Show Gist options
  • Save attatae/10436529 to your computer and use it in GitHub Desktop.
Save attatae/10436529 to your computer and use it in GitHub Desktop.
profiles controller snippet.rb
def index
if params[:interest]
@profiles = Profile.tagged_with(params[:interest], :on => :interests)
else
@profiles = Profile.all
end
if params[:skill]
@profiles = Profile.tagged_with(params[:skill], :on => :skills)
else
@profiles = Profile.all
end
end
@ballman
Copy link

ballman commented Apr 11, 2014

I think you are overwriting the @Profile when you pass only an :interest param. I'm assuming that only one of the :skill or :interest parameters will be sent at once, so the code should be:

def index
 if params[:interest]
  @profiles = Profile.tagged_with(params[:interest], :on => :interests)
 elsif params[:skill]
  @profiles = Profile.tagged_with(params[:skill], :on => :skills)
 else
  @profiles = Profile.all
 end
end

@attatae
Copy link
Author

attatae commented Apr 11, 2014

Thanks for helping with the code, @ballman. The earlier error is gone (scoping in tag cloud works); However, now when I click on "edit", the :interest and :skill tags do not show up. I can make a new profile, see :interests and :skills just fine on the Show page, but when I click to Edit the same profile, those :interests and :skills are not visible. I was't getting this error before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment