Ruby On Rails Helpers -- Using instance variables in helpers
Date : March 29 2020, 07:55 AM
I hope this helps . Depending on the level of detail for this quiz result you may actually want to use a partial. In which case the syntax would be: <%= render :partial => 'quiz/results', :locals => { :quiz => @quiz } %>
def quiz_result(quiz) # no need to call it "current" when we supply quiz
# do some stuff
end
|
rails can custom helpers use other helpers? (image_tag, radio_button_tag etc?)
Date : March 29 2020, 07:55 AM
Does that help Yo can do something like this in a helper method. Even pass a block with html some_helper.rb def nav_dropdown_item label
return nav_item(label, "#") unless block_given?
content_tag(:li, class: 'dropdown') do
link_to(t(label), "#", class: 'dropdown-toggle', data: {toggle: 'dropdown'}) +
content_tag(:ul, yield, class: 'dropdown-menu')
end
end
<%= nav_dropdown_item 'menu.admin.title' do %>
<% nav_item('menu.admin.chains', '/chains') +
nav_item('menu.admin.food_types', '/food_types') +
nav_item('menu.admin.street_types', '/street_types') +
nav_item('menu.admin.poi_sources', '/poi_sources') +
nav_item('menu.admin.poi_types', '/poi_types') %>
<% end %>
<%= nav_item 'menu.users', users_path %>
|
ruby on rails AbstractController::Helpers::MissingHelperError: Missing helper file helpers//
Date : March 29 2020, 07:55 AM
this one helps. I was having the same challenge and after reading all of the answers and finding no success. This is how I fixed the error: Open Finder and checked the path to my code. My path was myMac/Code/my apps.
|
Rails instance variables not shared between helpers in ApplicationController and app/helpers
Date : March 29 2020, 07:55 AM
it helps some times An instance variable is not a global variable - it is tied to a particular instance (hence the name). Rails allows you to access controller instance variables from a view. This works by copying the controller instance variables: the view_assigns methods in AbstractController::Rendering creates a hash of all the instance variables. Later on, the view object uses that hash to recreate the instance variables. When you say that it's as if there are local copies of the variable being made, that's pretty much exactly what is happening. def set_cost
controller.set_cost
end
|
Rails “helpers” are very specifically view helpers
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , To satisfy my supervisor (or code reviewer), I had to copy/paste all session helper code on every single controller file, since copying it in application_controller was not enough.
|