LearningBasics
LearningBasics

Reputation: 680

Rails: Restarting the server each time make change in code using console

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?

Upvotes: 1

Views: 465

Answers (2)

ecoding5
ecoding5

Reputation: 402

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

Upvotes: 0

Raj
Raj

Reputation: 22926

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!

Upvotes: 5

Related Questions