0

I have a controller (RoadsController) update action which I'm using to call a different view (views/road_surface/crop.html.erb). To meet other project requirements, I need to keep this file in a different view:

def update
  @road = Road.find params[:id]

  if @road.update_attributes params[:road]
    if params[:road][:road_surface].present?
      render "road_surface/crop" #I'd like to pass @road to my road_surface view here
    else
      redirect_to road_path @road.id
    end
  else
    render : action => 'edit'
  end
end

I need to pass the @road instance variable to the road_surface view. I've read this instructional on rendering: http://guides.rubyonrails.org/layouts_and_rendering.html but couldn't find what I was looking for. This seems simple enough but I'm definitely a Rails noob so I think I'm either missing something obvious or going about this the wrong way. Any ideas?

1 Answer 1

2

@road is a instance variable of the controller. All instance variables from the called controller method are available in the called view.

just do <%= @road.inspect %> in the view and you will see it print the attributes of the model instance.

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

Comments

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.