Reputation: 11
I have a Rails 2.3.11 controller that I'm trying to debug. It looks like this:
class AppleController < ...
# ...
def create
# ...
end
end
From the log, I have some parameters p
:
p = { ... }
What can I write at the console so that I can get an instance of AppleController that will work exactly like a regular instance with those parameters, and which will let me call .create
?
ac = AppleController.new
# What goes here?
ac.create
(Notice that just assigning ac.params = p
is not sufficient since there's no @request
object, etc.) Thanks!
Upvotes: 1
Views: 1390
Reputation: 36502
I think this is best done using the ActionController::Integration::Session class
e.g. to call the create method of your AppleController
require 'action_controller/integration'
app = ActionController::Integration::Session.new;
app.post('/apples', params) # assuming '/apples' is the path to your AppleController
puts app.response.inspect
Upvotes: 2
Reputation: 2064
If I am reading the question correctly, you can just call Apple.create(:something => "bah")
in the console. That should mimic what the controller does when it gets a post request.
Upvotes: -1