For example, when I entered some content into the database I used <% link_to ...%> for the links but when the actual page is displayed it doesn't execute this code. The view just prints it out literally.
executing ruby code stored in the database
- Anrake
- Posts: 4
- Starts: 3
- Wiki Edits: 0
- Location: Tokyo
Is there a way to make the view execute ruby code that is stored in the database when the field containing it is displayed?
For example, when I entered some content into the database I used <% link_to ...%> for the links but when the actual page is displayed it doesn't execute this code. The view just prints it out literally.
For example, when I entered some content into the database I used <% link_to ...%> for the links but when the actual page is displayed it doesn't execute this code. The view just prints it out literally.
- Vinayan
- Posts: 250
- Starts: 0
- Wiki Edits: 2
Hi Anrake,
You can execute ruby codes given in database with the help of stored procedures.
Eg:-
CREATE PROCEDURE mydb.my_stored_procedure()
BEGIN
$$ Insert Ruby Code $$
END
The stored procedure can be called from the rails application by executing the Call function
eg:- CALL my_stored_procedure()
You can execute ruby codes given in database with the help of stored procedures.
Eg:-
CREATE PROCEDURE mydb.my_stored_procedure()
BEGIN
$$ Insert Ruby Code $$
END
The stored procedure can be called from the rails application by executing the Call function
eg:- CALL my_stored_procedure()
2008-08-02 09:04 AM
- Bclennox
- Posts: 5
- Starts: 2
- Wiki Edits: 0
Anrake,
You might also try render :inline. I'm currently using this in a lot of places (probably more than I should be). For example, a page with some HTML/Erb content:
You might also try render :inline. I'm currently using this in a lot of places (probably more than I should be). For example, a page with some HTML/Erb content:
$ script/console
>> puts Page.find(1).content
<p>Check out my awesome <%= link_to 'blog', blog_path %>!</p>
and a view to render it:# app/views/page/show.html.erb
<%= render :inline => @page.content %>
2008-08-04 09:27 PM
- Rcs
- Posts: 1
- Starts: 1
- Wiki Edits: 0
Haha, I just started doing this and it's great fun. You can use Ruby's 'eval' method to execute a string as Ruby code. The second argument, 'binding', determines what context the code will execute in. You can try it in the console:
$ script/console
Loading development environment (Rails 2.1.0)
>> s = 'foo'
=> "foo"
>> eval "s='bar'", binding
=> "bar"
>> puts s
bar
=> nil
>> exit
See http://www.ruby-doc.org/core/classes/Kernel.html#M005948.
2008-08-20 11:17 AM
- Anrake
- Posts: 4
- Starts: 3
- Wiki Edits: 0
- Location: Tokyo
Thanks guys! render :inline seems to work best for me.