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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depends on the partial, what does it do, what methods it calls. But basically you have to see what templating engine it uses(erb, haml) and what calls does it make(if it calls other internal api’s etc).
Also if you are taking any data from the Database(using activerecord) then you will have to establish the connection to the Database yourself in the script and fetch the data.
Once you establish the connection, fetch all the data that you need on your partial.
Other than that, render is pretty basic.
render_to_string, is going to call the templating engine to translate it to html. If its HAML for example would be something like:
If your partial calls any of the rails API’s you would need to copy/or include those API’s and that gets complicated