In Rails it is not good practice to define @b somewhere you cannot see it being defined, as you may find it hard to figure our what's going on in the controller when you look back at it later on.
I suggest you set @b explicitly at the start of both the show and the index action: in other words, do repeat your
@b = Ece.find...
in each of the show and index actions - which is what you are already doing, I believe.
If you do want to clean up the controller code a bit, then do define a private function
private
def find_b(my_params)
@b = Ece.find_by_code(my_params)
end
so that now your controller show and index actions set @b this way
@b = find_b("#{params[:course]}")
Now you have cleaner code, but at the same time you immediately know by looking at the controller that you are setting @b and that you are using params to do so.
As for the link you want to add in your show action, don't find the course Course.find_by_courseCode in the view - keep the view cleaner - and move that to the bit controller. So now your show action in the controller will have a line like this
@course = Course.find_by_id( @b.id )
and you can write your view link more cleanly as
<%= link_to 'Forum', @course, :class=>"question_button round" %>