Question

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 !@panel.available_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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top