JDutil / contact_us

Gem providing simple Contact Form functionality with a Rails 3+ Engine.
http://contact-us-demo.herokuapp.com
MIT License
135 stars 57 forks source link

missing Controller #16

Closed sam452 closed 12 years ago

sam452 commented 12 years ago

This is me speaking as a newbie user, but following the instructions successfully I think, when I follow: "Visit your website and navigate to /contact-us to see the form in action." I've made a route called, "resources :contact_us". I did this because my app says there was no route to "/contact_us". Then it complained there was no controller. I made an empty controller and it complains there is no index view. How far down should I take this? Apparently, there is more that is understood by your audience than I do so far, or I've gone down the wrong path in setting up a route. What am I not understanding? thx, sam

JDutil commented 12 years ago

You should navigate to /contact-us but your indicating that you navigated to /contact_us which would not be picked up by your routes. If you want to create a custom route like /contact you should be able to do this in your routes file:

match 'contact' => 'contact_us/contacts#new'

Note that the contacts controller is namespaced under contact_us which allows you to add your own contacts controller without conflicting with this library.

sam452 commented 12 years ago

Thank you. Using the custom route above, when I place 'http://localhost:5000/contact' into my URL of the browser, I get a routing error, 'uninitialized constant ContactUs'. I have my empty class ContactUsController < ApplicationController. I even put a new method in it to match the contacts#new. I did not change anything re: contact_us setup, just adding stuff to get it to work. Are you saying that after following the instructions, a developer has to create controllers, views to support your library? Reading your last note suggests not. A routing error suggests that I did something wrong there. As a test, I removed the contact_us_controller.rb file since it appears your suggested route points to the view files. It still does not recognize the custom route. Is it assumed someone using the lib is to create their own controller? unsure, sam

JDutil commented 12 years ago

No everything should just work unless you want to customize. Please remove any custom controller / views etc... you've added just trying to make it work. You can even remove the custom route and just use the ones out of the box. I was using that as an example of a proper way to make the route, rather than using resources :contact_us.

Try visiting: http://localhost:5000/contact-us

That should just work for you since you mentioned before that you tried http://localhost:5000/contact_us which is incorrect in version 0.3.0+ Note the difference between contact-us and contact_us as it matters.

I'm not sure why adding the custom route I mentioned did not work for you without having a look at your code. The best way for me to describe how the routes should look though is to show you the Gems routes, which you can see in: https://github.com/jdutil/contact_us/blob/master/config/routes.rb

sam452 commented 12 years ago

Thank you, my gem file shows: gem 'contact_us', '~> 0.4.0.beta'

Going to 'http://localhost:5000/contact-us' yields the routing error "No route matches [GET] "/contact-us". So clearly there is something funny about my environment that is out of the norm. My ruby is 1.9.3p0 and my rails is 3.1.3. Therefore, I do not expect you to fix my problems. For completeness, the code is here: https://github.com/sam452/Vitae2 but this now appears to be my problem. Thanks for hanging with me this far.

JDutil commented 12 years ago

Did you remember to restart your web server after running the bundle install command? It could be as simple as stopping and starting webrick or whatever server your using for development.

sam452 commented 12 years ago

Yes, you are right. I was unsure since route changes were happening without restarting, but I can affirm that it does work as expected. Thanks for sticking with me, this issue is closed.

JDutil commented 12 years ago

No problem I hope you find the gem useful! I've made the same mistake plenty of times. Always restart the web server after bundling gems. Not sure what your using for a web server, but if it is aware of tmp/restart.txt files like pow (which I use) or passenger you can just do:

$ bundle && touch tmp/restart.txt

That will bundle your Gemfile updates and the next request you make to the server restarts the application.