0

Hello I am having difficulties understanding why the parameter is not passing to the view.

controller

class UsersController < ApplicationController
  include UsersHelper

  before_filter :set_user, :set_categories
  def show
    @test = get_test()
  end
end

helper

module UsersHelper
   def get_test()
     puts "hello world"
   end
end

view

test:  <%= @test %> 

What is being displayed test:

Can someone please give me some assistance of why hello world is not being displayed? Thanks!

--Edit-- It seems like I am not able to even pass any variable messages to the view I added...

controller

@message = "How are you"

view

<p><%= @message %></p>

And How are you is not displaying.

1
  • have you defined @message inside relevant action? Commented Jan 26, 2014 at 23:38

1 Answer 1

3

In your get_test function, you are printing a string instead of returning the string. To return a string:

module UsersHelper
   def get_test()
     "hello world"
   end
end
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks that did solve the problem! would you have happen to know how to solve my edit?
How would you return a variable, would it just be @hello = "hello world"? Or would it just hello = "hello world", and it would return the local variable?
Sorry. I don't quite understand you. You mean to assign a string to a variable? To return a string from the function you do return "hello world". To let a view access the variable you often have to assign it to a instance variable, which is @hello = "hello world". hello without @ would be local variable.

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.