AustinT
AustinT

Reputation: 2036

Ruby on Rails passing controller variables to view

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.

Upvotes: 0

Views: 62

Answers (1)

revolver
revolver

Reputation: 2405

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

Upvotes: 3

Related Questions