Created
October 9, 2014 17:26
-
-
Save zackn9ne/e6d76bc03d6c34c0722d to your computer and use it in GitHub Desktop.
basic controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index | |
| @museums = Museum.all | |
| # @museums = Museum.search_for(params[:q]) | |
| # go into the models and rails.rb in order to allow the .search_for method to be available in a sort of whitelisted way | |
| end | |
| def new | |
| @museum = Museum.new | |
| end | |
| def show | |
| load | |
| end | |
| def edit | |
| load | |
| end | |
| def update | |
| @museum.update safe_painting_params | |
| redirect_to @museum | |
| end | |
| def destroy | |
| @museum.delete | |
| end | |
| def create | |
| #rails 3 way @museum = Museum.create(params[:painting]) | |
| @museum = Museum.create(safe_painting_params) #create initialisases and saves to the database | |
| if @museum.save | |
| redirect_to @museum | |
| else | |
| #fail | |
| # redirect_to museums_path | |
| render 'new' | |
| end | |
| end | |
| private | |
| def safe_museum_params | |
| params.require('museum').permit(:name) | |
| end | |
| def load | |
| @museum = Museum.find(params[:id]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment