Passing local variables to a view from controller

后端 未结 5 878
鱼传尺愫
鱼传尺愫 2021-02-14 05:57

I am not able for some reason to pass local variables to the show view...

In my controller i have simply:

def show
  render template: \"books/show\", :re         


        
5条回答
  •  野的像风
    2021-02-14 06:23

    First I am wondering why would you need the template:. Are you on Rails 2.x? If not, then the :template option is no longer required. You should be able to get along fine with just

    render "books/show"

    Second do you need to specify the template? What is the controller you want to render from? If that's BooksController, then you don't need the template path either, which makes the line being just

    render

    That's without the variables yet. Now, I just checked, and a simple:

    render locals: { resource: "Some text" }

    as well as:

    render 'books/show', locals: { resource: "Some text" }

    works for me just fine. Maybe earlier Rails versions treated 'resource' as some kind of a keyword? Don't know, but the above Worksforme™ in both forms.

提交回复
热议问题