0

I am new to RoR .I want my controller to instatiate an existing class from lib .

Collect data in the form of a string and throw the result on the view.erb.Can I do that.

Do i have to create a new model object and that should that model object inturn call the lib class.

0

1 Answer 1

1

Not really sure what you want to do.

If you used a library class - a module for example - its automatically instantiated, when you use 'include'

If you just have a generic class, and you included it somewhere, then you already have the class object loaded and can call methods on it. Or you just create an instance manually with 'object = new MyClass'. And then call whatever you like on 'object'.

Whatever Information you collect inside the controller method, you can access in the view, when you place an '@'-Symbol before your variable. So if you want your show.html.erb look like this:

<h1>My String:</h1>
<%= @mystring %>

then you have to do something like this in your controller:

def show
  ...
  @mystring = MyClass.get_my_cool_string
  ...
end

Hope that helps...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.