Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Controller redirect_back_or_to using the Sorcery gem?

To save myself the trouble of reposting it all here, I'll just post the Stack Exchange link:


I hope someone can help me with this (I'm sure Maciej will have something to say! ;-) )

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Andrew, I downloaded and deployed your site locally, but it doesn't have the button you mentioned and does not have any controllers, so I'm not sure where to even start.

Yes, it's the create_testimonials branch.

I didn't use Devise, because I thought it was superfluous to my needs! I still think I'll be ok with Sorcery; it can even do mailers, but it'll be a bummer if it turns out to be a bad decision.

3 Answers

Solved. For anyone who's curious, you can see the explanation in the original stack overflow link.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Check out my pull request. Seems it fixed your problem. Let me know if it's still not working properly.

Thanks for the bonus fix! ;-) (fixing the problem of being able to edit other people's testimonials by changing the address in the browser manually).

def correct_user
      if @testimonial.user !=current_user
        redirect_to root_path

This was one of those times when I saw the fix and groaned and thought, "I should have spotted that". What I'd done was to initially follow an example from another app, which didn't work. If I'd stopped to think about it on my own to begin with, I might have come up with this quite obvious fix myself. Thanks!

(I'm going to talk about the other stuff when I've finished going through it)

Ok, I didn't actually merge your pull, because I haven't done that before, but I DID apply all of your changes manually, except for the apparent change to one of the migration files (except you didn't actually change it??) Anyway, probably not important.

Anyway, I experimented with applying the changes, but it didn't work. But see my notes on the pull request for the strange thing I discovered.

Thanks for all your help so far! Much appreciated!


Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I deleted one of the migration files, because it was in the wrong order (adds a column to a table that does not exist yet when migrated) and when moved to the end of migrations, it adds a field that already exists. Try downloading your project and running rake db:migrate on it and you'll see.

Ok, I've deleted that thanks