Question

I have a helper_method that allows links to escape from a subdomain. However it is impacting my videos_controller, as it essentially seems to negate the 'current_event' method when not in the events controlller.

I've tried several dozen different ways over the last 4 days to make it so I can still escape my links from the subdomain, but still allow the videos_controller to work.

I think the best way to achieve this is to exclude the videos_controller from the helper method, but I'm not sure how (or if it is actually the best way forward - I'm obviously a noob!) Any suggestions please?! Relevant code below:

module UrlHelper
  def url_for(options = nil)
      if request.subdomain.present? and request.subdomain.downcase != 'www' and !options.nil? and options.is_a?(Hash) and options.has_key? :only_path and options[:only_path] 
        options[:only_path] = false 
      end
      super
  end
end

Videos_controller

def new
    if current_event?
      @video = current_event.videos.new
    else
      @video = Video.new
    end
  end

  def create
    if current_event.present?
      @video = current_event.videos.new(params[:video])
      @video.user_id = current_user.id
       key = get_key_from_the_cloud
      @video.key = key
    else
      @video = current_user.videos.new(params[:video])
      @video.user_id = current_user.id
      key = get_key_from_the_cloud
      @video.key = key
    end
    if @video.save
      flash[:success] = "Video uploaded!"
      redirect_to root_url(subdomain: => current_event.name)
    else
      flash[:error] = "#{@video.errors.messages}"
      render :new
    end
  end

current_event method

  def current_event
    if request.subdomain.present?
      @event = Event.find_by_name(request.subdomain)
    end
  end
Was it helpful?

Solution

Did you take a look at this post yet?

You might want to create a new function test that only does something like

module UrlHelper
  def test
    puts "Test is called"
  end
end 

If that works you know its not including that fails but it has to be the method. Otherwise you know the module is not included and you can narrow down the search.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top