I have a DateTime class instance variable @current_year = DateTime.now.year, which I have set into a footer partial. This partial is rendered across several of my clientside pages (and across multiple controllers as <%= render 'layouts/page_footer' %> in the main body of the page - the layout/application.html.erb page is reserved for the site navigation, so the format will not accommodate it there. While I could declare it for every page method it appears on in the controller, I'd find something a little more DRY. Is there a single place I can define my time variable to call in my layout component?
Choosing a controller for a layout class instance variable in Rails
205 Views Asked by Boucherie At
2
There are 2 best solutions below
Related Questions in RUBY-ON-RAILS
- How to display legend box in tooltip text for amCharts 5 in Rails application?
- how to integrate cashfree payment gateway in ruby on rails project
- RSpec Capybara throwing Selenium error when trying to click a button with browser confirm
- rails minitest not picking up fixture properly, instance variable not percolating
- Duplicate GET requests - Rails & Heroku
- How to stub out current_user in JWT model for Rspec?
- NameError in Home#index
- Verifying Google Identity OAuth2 token with Ruby
- Error WebMock::NetConnectNotAllowedError in testing with stub using minitest in rails (using Faraday)
- why is mission_control-jobs erroring with load path error?
- Rescuing validation errors from a polymorphic association
- New error on random number assigned to local variable , Rails
- How to fix error in model with gem lockbox
- Images uploaded via Active Storage not displaying in Active Admin or on certain devices
- controller test_methods generating two errors intermittently
Related Questions in LAYOUT
- Why does my ViewPager not show anything when i add a scrollview?
- Is it possible to set height value so that it is both inheritable and acts as min-height?
- Background image not rendering under AppBar with React Material-UI
- HBox doesn't fill parent GridPane when rotated by 90 degrees
- issue when trying to use trained layoutlmv3
- Does anyone know how to make iPad layout the same as iPhone's? Size wise the text and overall layout get's smaller when I run the app on the iPad
- How can I place near (vertically) two TextView?
- SplitView elements both in horizontally and vertically in qml
- Splitview inside a Layout in QML is not working properly
- How do I fix fragment overlaping with main_activity fragment in Kotlin
- Why are my Buttons overlapping in QML ColumnLayout?
- How to make a face using Constraint Layout?
- Preventing SwiftUI Frame Size Changes from Affecting Window Size in a macOS App
- React-layout dynamic content?
- Can I scale layout to a smaller screen?
Related Questions in CONTROLLER
- godot lean mechanic makes camera glitch
- Why Jackson needs a default constructor?
- How to convert an HTML string to an escaped one?
- how to connect acb-004 controller using python
- Store files on gdrive from controller
- Laravel form action not accepting $order->id but accepting hard coded value
- Input Field Required
- Can you help a tag look at the static resource path without looking at the controller
- Reuse controller paths for a Spring Boot Controller
- How do i change a single value data into an array table in Laravel Jetstream vue stack?
- No route found in Shopware6/symfony
- Player sprite not changing when moving left or right when using a Playstation 5 Controller, but sprite changing when using keyboard controls
- problem with laravel view not extending layout.blade.php with out assets file . What can possibly be the problem?
- How apply machine learning code to ryu controller
- Nginx custom error page unexpected error reading return code: strconv.Atoi: parsing "": invalid syntax. Using 404
Related Questions in PARTIAL-VIEWS
- Accessing value from dynamic object
- Return partial View if model state was not valid
- MVC Login form in all page i want using PartialView
- Binding Model data to form in ASP.NET MVC
- MVC - Html.DropdownListFor disappearing when selectpicker class is added to HTML attributes
- Model is null while rendering view
- How to reference dropdown in MVC Application
- how to add partial hbs file inside master hbs file in sugarcrm
- Laravel trying to add custom css file inside a partial view with @include
- Passing model data to partial view
- Update partial view on non-MVC Asp.Net Core 6 RazorPages with Ajax
- C# MVC multiple loading javascript
- Is there any way we can use .cshtml partial view in a React web application?
- Partial form saving and loading without full page postback in ASP.NET Core 7 Razor Pages?
- Create a partial view in MVC c# that use a Javascript object with some parameter
Related Questions in CLASS-INSTANCE-VARIABLES
- Get the variable associated with a JPanel component from a component array
- Class Inheritance python require fill child class name
- aiohttp instance variable values shared by different users?
- How to get the maximum value among the arguments of class objects in Python?
- Can I use a class instance as an argument for a generic in java?
- getting field value from class instance in python
- instantiate typescript class instance with constructor parameters
- Can't figure out how to create a "list" instance variable using class in Python
- Why the list variable named nodes in the class is taking the output of the previous instance of the class?
- Java how to call method in another class
- @coffee_hour = Plan.find_by_event(:coffee_hour) ...Is it possible to link using a variable like this?
- Does Ruby's define_method have special access to instance variables?
- Why equality check for instance of Struct/Class are different?
- Create a new instance of parent's class variable for each child class
- Django Field Instances overriding each others arguments
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You could add a
set_yearaction in yourApplicationController, something like:And then call it in a
before_actionin your relevant controller actions. Something like:Alternatively and riffing off MrYoshiji's comment, you could create a
current_yearaction inApplicationController, something like:In which case, you could use
current_yearin your partial instead of@current_year. And then, as MrYoshiji says, you could move that into a helper if that sort of things floats your boat. Something like:The upside, I suppose, of moving
current_yearinto a helper is that it de-clutters yourApplicationController. The downside, I further suppose, is that it obsfucates (to some degree), the source of thecurrent_yearaction. Again, you'll have to take your boat floating coefficient into consideration.BTW,
@current_yearisn't aDateTime. It's aFixnum.