Created
November 20, 2013 23:45
-
-
Save salami-art/7573337 to your computer and use it in GitHub Desktop.
'books' route called with redirect_to assigns variable as expected, Action :index (same page) called with render doesn't.
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
class BooksController < ApplicationController | |
def index | |
@books = Book.all # # this variable doesn't get loaded with " render " | |
respond_to do |format| | |
format.html | |
format.yaml { render text:@books.to_yaml } | |
format.json { render text:@books.to_json } | |
end | |
end | |
def show | |
@book = Book.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.yaml { render text:@book.to_yaml } | |
end | |
end | |
def new | |
@book = Book.new | |
end | |
def create | |
@book = Book.new(book_params) | |
if @book.save | |
redirect_to book_path(@book) | |
else | |
render :new | |
end | |
end | |
def edit | |
@book = Book.find(params[:id]) | |
end | |
def update | |
@book = Book.find(params[:id]) | |
end | |
def destroy | |
@book = Book.find(params[:id]) | |
@book.destroy | |
render :index #redirect_to books # here is where either render or redirect_to is called | |
end | |
private | |
def book_params | |
params.require(:book).permit(:title, :text, { author_attributes: [:name]}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment