     add_socket(mount, Dict.merge(opts, alias: chan_alias), chan_block)
   end
   defp add_socket(mount, opts, chan_block) do
-    quote bind_quoted: [mount: mount, opts: opts], unquote: true do
-      if Scope.inside_scope?(__MODULE__) do
-        raise """
-        You are trying to call `socket` within a `scope` definition.
-        Please move your socket and channel definitions outside of any scope block.
-        """
-      end
-
-      @phoenix_socket_mount mount
-      @phoenix_transports opts[:via]
-      @phoenix_channel_alias opts[:alias]
-      get  @phoenix_socket_mount, Phoenix.Transports.WebSocket, :upgrade, Dict.take(opts, [:as])
-      post @phoenix_socket_mount, Phoenix.Transports.WebSocket, :upgrade
-      get  @phoenix_socket_mount <> "/poll", Phoenix.Transports.LongPoller, :poll
-      post @phoenix_socket_mount <> "/poll", Phoenix.Transports.LongPoller, :publish
-      unquote(chan_block)
-      @phoenix_socket_mount nil
-      @phoenix_transports nil
-      @phoenix_channel_alias nil
+    quote do
+      try do
+        mount = unquote(mount)
+        opts  = unquote(opts)
+
+        if Scope.inside_scope?(__MODULE__) do
+          raise """
+          You are trying to call `socket` within a `scope` definition.
+          Please move your socket and channel definitions outside of any scope block.
+          """
+        end
+
+        @phoenix_socket_mount mount
+        @phoenix_transports opts[:via]
+        @phoenix_channel_alias opts[:alias]
+        get  @phoenix_socket_mount, Phoenix.Transports.WebSocket, :upgrade, Dict.take(opts, [:as])
+        post @phoenix_socket_mount, Phoenix.Transports.WebSocket, :upgrade
+        get  @phoenix_socket_mount <> "/poll", Phoenix.Transports.LongPoller, :poll
+        post @phoenix_socket_mount <> "/poll", Phoenix.Transports.LongPoller, :publish
+        unquote(chan_block)
+        @phoenix_socket_mount nil
+        @phoenix_transports nil
+        @phoenix_channel_alias nil
+      after
+        :ok
+      end
     end
   end
 

      end

    quote do
      resource = Resource.build(unquote(path), unquote(controller), unquote(options))

      parm = resource.param
      path = resource.path
      ctrl = resource.controller
      opts = resource.route

      Enum.each resource.actions, fn action ->
        case action do
          :index   -> get    path,                            ctrl, :index, opts
          :show    -> get    path <> "/:" <> parm,            ctrl, :show, opts
          :new     -> get    path <> "/new",                  ctrl, :new, opts
          :edit    -> get    path <> "/:" <> parm <> "/edit", ctrl, :edit, opts
          :create  -> post   path,                            ctrl, :create, opts
          :delete  -> delete path <> "/:" <> parm,            ctrl, :delete, opts
          :update  ->
            patch path <> "/:" <> parm, ctrl, :update, opts
            put   path <> "/:" <> parm, ctrl, :update, Keyword.put(opts, :as, nil)
        end
      end

      unquote(scope)
    end
  end


      end

    quote do
      try do
        opts     = Keyword.put(unquote(options), :singular, true)
        resource = Resource.build(unquote(path), unquote(controller), opts)

        path = resource.path
        ctrl = resource.controller
        opts = resource.route

        Enum.each resource.actions, fn action ->
          case action do
            :show    -> get    path,            ctrl, :show, opts
            :new     -> get    path <> "/new",  ctrl, :new, opts
            :edit    -> get    path <> "/edit", ctrl, :edit, opts
            :create  -> post   path,            ctrl, :create, opts
            :delete  -> delete path,            ctrl, :delete, opts
            :update  ->
              patch path, ctrl, :update, opts
              put   path, ctrl, :update, Keyword.put(opts, :as, nil)
          end
        end

        unquote(scope)
      after
        :ok
      end
    end
  end

