I have a helpers in Rails app that return some data based on a variable set in controller: like:
def title
base_title = "Unikernel"
if @title.nil? then
base_title
else
"#{base_title} | #{@title}"
end
end
And in controller (usually in each action) I set the value, eg:
@title = "Solutions"
now when I process some result I get from form submission, if something’s wrong I say:
render action: "edit"
or
render "new"
When I’m on the rendered page the variables aren’t initialized and so on.
What should I do with this problem?
Usually, when something is wrong while updating, you find yourself in the update action. When something goes wrong while creating, your error message gets shown by the create action. Did you set your variable in your create and update action, too?
When you submit your form and get errors, you will get
@titlefrom yourcreateaction and if you haven’t set it in create,@titlewill be nil.When you call
render, you are not redirecting to another action, hence you are still inupdate.