I am using accessing my controllers methods from console with rails c command. The problem I am facing is that each time I have reflect any changes made in the code then I have to first exit and restart . Is these any way to fix this problem?
Asked
Active
Viewed 374 times
0
-
Can you show which command you're exactly running to fetch the data in your console? – Surya Sep 12 '14 at 11:38
-
i am just calling static method of some class and this method prints the output on screen – LearningBasics Sep 12 '14 at 11:56
-
reload! is not working as desired so that rules out that option – LearningBasics Sep 12 '14 at 11:57
-
You need to tell exactly where you're facing the issue. It's not possible to help you with hit and trials, and assumptions. – Surya Sep 12 '14 at 12:16
2 Answers
4
From your rails console, type reload!
2.1.2 :012 > reload!
Reloading...
=> true
2.1.2 :013 >
to reload all your Rails application code. No need to exit and start console again!

Raj
- 22,346
- 14
- 99
- 142
-
3Yes, however there is this caveat: If you have any pre-existing objects, they will still be based on the previous code. So it's important to re-initialize any objects you are working with after a `reload!` command. – platforms Sep 12 '14 at 12:17
-
^^ Exactly! + those objects will not have updated methods with the updated code and you may end up getting weird errors! – Surya Sep 12 '14 at 12:18
0
If you have associations you can do this:
class home
belongs_to :renter
end
class renter
has_one :home
end
Let's say you start with home attributes:
home = Home.where(renter_id: 1)
=> #< Home id: 1, alarm: "no">
renter = Renter.find(1)
renter.home.alarm
=> "no"
Then you modify home:
home.alarm = "yes"
home.save
When you do:
renter.home
=> #< Home id: 1, alarm: "no"> # it still returns no
renter.home(true)
=> #< Home id: 1, alarm: "yes">"
# you can use (true) to make sure your association
# change is reflected, it basically queries the server again

ecoding5
- 404
- 6
- 19