Linked Questions
22 questions linked to/from How can I call controller/view helper methods from the console in Ruby on Rails?
62
votes
2
answers
50k
views
How to use all view and helper methods inside of Rails console for Rails 2.x and 3.x? [duplicate]
helper.method_name worked in some version of Rails... are there ways that work in both Rails 2.2.2, 2.3.5, and 3.0.1? (to use all view and helper methods)
31
votes
2
answers
11k
views
Why do date helpers not work in Rails console?
I have a datetime attribute on a record:
1.9.3p194 :024> f.last_contact
=> Thu, 11 Aug 2011 00:00:00 UTC +00:00
But when I try time_ago_in_words at the console, it doesn't work:
> ...
22
votes
3
answers
20k
views
How do I render a partial from the Rails console?
I'm using Rails 4.0.3. How do I render a partial from the Rails console?
15
votes
3
answers
26k
views
Calling an ApplicationController method from console in Rails
In Rails, supposing that the file is already loaded, how it is possible to call my_method from this example from console?
# some_file.rb
class MyClass < ApplicationController::Base
def ...
15
votes
4
answers
10k
views
Rails 4 strong parameters failing when creating instances in rails console
Probably doing something stupid here, but here's my basic cookie cutter class:
class League < ActiveRecord::Base
private
def league_params
params.require(:full_name).permit!
...
6
votes
1
answer
12k
views
Rails calling a controller action from the console
I have a controller sessions that can create session.
I'd like to call it from the console, like controller.create.
Here is the action:
def create
#raise request.env["omniauth.auth"].to_yaml
...
5
votes
3
answers
5k
views
How do I generate a CSRF token from the Rails console?
I'm trying to make an authenticated post request, and I need the CSRF. When I log in, it isn't generating the _csrf_token for some reason:
2.0.0p247 :126 > app.post '/community_members/login', {"...
3
votes
3
answers
4k
views
Run helpers inside Rails 5 console
I'm trying to test out some helpers in the rails console.
I read another answer that describes some techniques.
In my first attempt I start calling my helpers on the helpers object:
[10] pry(main)&...
6
votes
2
answers
4k
views
How can I run a controller concern method from the console?
If I have a controller concern, for example:
module MyConcern
def concern_method param
puts param.inspect
end
end
How can I test the method concern_method from the console?
Using methods ...
2
votes
2
answers
12k
views
Rails trying to call controller method from console
I'm trying to create a cron job using the whenever gem to send birthday reminders to users and i want this cron to run everyday.
I have the whenever gem working, but my cron job keeps erroring out. I'...
5
votes
3
answers
2k
views
Should I move my custom methods to model from controller?
Let's say I have a Product model and ProductsController. Controller has all the standard CRUD method and Product does all kinds of validations etc.
Here is an issue.
I have several custom very ...
4
votes
1
answer
2k
views
How to route and render (dispatch) from a model in Ruby on Rails 3
I want to dispatch (route and render) from a model. (I only care about GET requests and I ignore Accept: headers, so I only look at PATH_INFO.)
# app/models/response.rb
class Response < ...
3
votes
1
answer
2k
views
I thought Ruby on Rails "script/console" can let me do "render :text => 'hello' " but it says render is not defined?
I thought Ruby on Rails "script/console" can let me do "render :text => 'hello' " but it says render is not defined?
4
votes
2
answers
1k
views
Why can't I call an ActionView method from the Rails Console?
I'm trying to do a little testing of the number_to_currency method, but no matter how I try and call it in the console I'm out of luck it seems.
ActionView::Helpers::NumberHelper::number_to_currency ...
7
votes
1
answer
2k
views
Rendering a partial from a ruby script or console
Is it possible to render a partial from inside a ruby script or from the the rails console?
How would one go about doing this?