0

I want to render action if my model is not valid.

render "book_page"

https://gist.github.com/f7259eb79d1f2c951036

But for now @prices_per_night and @number_of_nights are nil when i click submit button. How to prevent this?

I tried to move this form to partial but it now happend, because I cant render only partial. Or Am I wrong?

3
  • What do you mean by " @prices_per_night and @number_of_nights are nil. How to Prevent this?" How is this relevant, are you trying to set those as global variables? Commented Jul 29, 2012 at 12:27
  • I think you may be confusing what to refer to variables as, check out their definitions here, should your title be "How to send instance variables when rendering a partial"?? Commented Jul 29, 2012 at 12:30
  • Sorry, You are right, just changed title Commented Jul 29, 2012 at 12:47

1 Answer 1

1

Using render does not make Rails call the relevant method, book_page, in the controller. It proceeds directly to book_page.html.erb and, at this point, no method has set your instance variables so they appear nil.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so which method should i use instead of render?
I don't think anything stops you from calling book_page explicitly before calling render. Perhaps you should do both (or set the instance variables and call render) in some appropriate helper method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.