0

I'm trying to show info into a dialog. I want such info to be loaded from a view (template). The thing is that, when i use

<%= render template:'panels/product_specifications' %>

it tries to load the info but, as i have global variables used in my view that were defined in the controller, and the controller isn't executed it throws me:

undefined method `banner_image_with_arrows_filename' for nil:NilClass

Extracted source (around line #2):

1: 
2: - banner_image = "banners/panels/#{@panel.banner_image_with_arrows_filename}"
3: #image-info
4:   %table
5:     %tr

@panel variable is defined in controller here:

def load_panel
    @panel = Panel.find_or_build_from_id(params[:id])
    if [email protected]_in_market?(market)
      add_flash_notice(t("pages.panel.text.not_available_in_market", :market => market.name), true)
    end
end

in a before_filter.

I have also tried with render partial:'panels/products_specifications (having underscored 'product_specifications.html.erb' first), render action:'panels/product_specifications', controller:'product_specifications with different errors.

How can i load that partial or view from another with the controller being executed too?

EDIT:

To give you a big picture, what i'm trying to do is to show the user (when he passes the mouse over a link) a dialog with a preview of what he will see if he click that link.

3
  • Where are you calling render_to_string? In a view? Commented Dec 27, 2013 at 7:46
  • render partial:'panels\products_specifications is that the right path ? It should have been render partial: 'panels/products_specifications' Commented Dec 27, 2013 at 8:33
  • @polarblau: sorry, i must have been very sleepy when i post the question. I have corrected ir with only render and render partial: 'panels/products_specifications' as it is how i did it in my code Commented Dec 27, 2013 at 15:00

1 Answer 1

2

If I understand as well, you hit a action that execute the method load_panel with a before_filter and, the view associated, you're trying to render a template with the variable.

The first thing you should to try is to see if there is a record returned by Panel.find_or_build_from_id(params[:id]). You can use the puts method or use a debugger like pry.

You can also try to do this <%= render template:'panels/product_specifications', panel: @panel %> and use panel as a local variable in your template like this : banners/panels/#{panel.banner_image_with_arrows_filename}.

I think a best practices can be to use a presenter.


Final answer after a chat

You must to use ajax to show a new panel and hit a controller action. You can see an example here.

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

7 Comments

it never gets to the controller. I have put a debugger breakpoint and also a puts "------------------------" to be printed in the console, but it never gets there. I don't know if render doesn't make use of the controller,. i can't use <%= render template:'panels/product_specifications', panel: @panel %>, since @panel is not defined in the page i have the links that will show the dialog on click
render will not hit a controller method. You must to use a presenter or create the variable on the controller's action used with the route.
it's not a controller method, is the action. Maybe i'm missunderstanding something. here it is my controller, view and route fpaste.org/64549. What is a presenter?
If I understand, the main problem is than the action product_specifications is never triggered. Try to replace your route with this get '/panels/product_specifications' (add a / at the beggining).
|

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.